How do I split a string on a delimiter in Bash?

You can set the internal field separator (IFS) variable, and then let it parse into an array. When this happens in a command, then the assignment to IFS only takes place to that single command’s environment (to read ). It then parses the input according to the IFS variable value into an array, which we can then iterate over. This example will parse … Read more

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

Revised Answer (Feb 12, 2014) Original Answer Caveats: https://stackoverflow.com/a/21210966/89391 From: Using boolean variables in Bash The reason the original answer is included here is because the comments before the revision on Feb 12, 2014 pertain only to the original answer, and many of the comments are wrong when associated with the revised answer. For example, Dennis Williamson’s … Read more

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

Revised Answer (Feb 12, 2014) Original Answer Caveats: https://stackoverflow.com/a/21210966/89391 From: Using boolean variables in Bash The reason the original answer is included here is because the comments before the revision on Feb 12, 2014 pertain only to the original answer, and many of the comments are wrong when associated with the revised answer. For example, Dennis Williamson’s … Read more

How to mkdir only if a directory does not already exist?

Try mkdir -p: Note that this will also create any intermediate directories that don’t exist; for instance, will create directories foo, foo/bar, and foo/bar/baz if they don’t exist. Some implementation like GNU mkdir include mkdir –parents as a more readable alias, but this is not specified in POSIX/Single Unix Specification and not available on many common platforms like macOS, various BSDs, and various commercial … Read more

How to mkdir only if a directory does not already exist?

Try mkdir -p: Note that this will also create any intermediate directories that don’t exist; for instance, will create directories foo, foo/bar, and foo/bar/baz if they don’t exist. Some implementation like GNU mkdir include mkdir –parents as a more readable alias, but this is not specified in POSIX/Single Unix Specification and not available on many common platforms like macOS, various BSDs, and various commercial … Read more

How to run a PowerShell script

Launch Windows PowerShell, and wait a moment for the PS command prompt to appear Navigate to the directory where the script livesPS> cd C:\my_path\yada_yada\ (enter) Execute the script:PS> .\run_import_script.ps1 (enter) What am I missing?? Or: you can run the PowerShell script from cmd.exe like this: according to this blog post here Or you could even run your PowerShell script from … Read more

How do I parse command line arguments in Bash?

Bash Space-Separated (e.g., –option argument) Output from copy-pasting the block above Usage Bash Equals-Separated (e.g., –option=argument) Output from copy-pasting the block above Usage To better understand ${i#*=} search for “Substring Removal” in this guide. It is functionally equivalent to `sed ‘s/[^=]*=//’ <<< “$i”` which calls a needless subprocess or `echo “$i” | sed ‘s/[^=]*=//’` which calls two needless subprocesses. Using bash with getopt[s] getopt(1) limitations (older, … Read more