How do I compare two string variables in an ‘if’ statement in Bash? [duplicate]

This question already has answers here: How to compare strings in Bash (11 answers) Closed 3 years ago. I’m trying to get an if statement to work in Bash (using Ubuntu): #!/bin/bash s1=”hi” s2=”hi” if [“$s1” == “$s2”] then echo match fi I’ve tried various forms of the if statement, using [[“$s1” == “$s2”]], with … Read more

How does “cat

I needed to write a script to enter multi-line input to a program (psql). After a bit of googling, I found the following syntax works: cat << EOF | psql —params BEGIN; `pg_dump —-something` update table …. statement …; END; EOF This correctly constructs the multi-line string (from BEGIN; to END;, inclusive) and pipes it … Read more

How to run a PowerShell script

How do I run a PowerShell script? I have a script named myscript.ps1 I have all the necessary frameworks installed I set that execution policy thing I have followed the instructions on this MSDN help page and am trying to run it like so: powershell.exe ‘C:\my_path\yada_yada\run_import_script.ps1’ (with or without –noexit) which returns exactly nothing, except … Read more

How can I declare and use Boolean variables in a shell script?

I tried to declare a Boolean variable in a shell script using the following syntax: variable=$false variable=$true Is this correct? Also, if I wanted to update that variable would I use the same syntax? Finally, is the following syntax for using Boolean variables as expressions correct? if [ $variable ] if [ !$variable ] 2 … Read more

How do I parse command line arguments in Bash?

Say, I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile or this one: ./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile What’s the accepted way of parsing this such that in each case (or some combination of the two) $v, $f, and $d will all be set to true and … Read more