Top "Bash" questions

For questions about scripts written for the Bash command shell.

Syntax for a single-line Bash infinite while loop

I am having trouble coming up with the right combination of semicolons and/or braces. I'd like to do this, …

bash loops while-loop
Find and Replace Inside a Text File from a Bash Command

What's the simplest way to do a find and replace for a given input string, say abc, and replace with …

bash ssh replace scripting ironpython
How to redirect output to a file and stdout

In bash, calling foo would display any output from that command on the stdout. Calling foo > output would redirect …

linux bash file-io io stdout
How to run the sftp command with a password from Bash script?

I need to transfer a log file to a remote host using sftp from a Linux host. I have been …

bash shell unix ssh sftp
In Bash, how can I check if a string begins with some value?

I would like to check if a string begins with "node" e.g. "node001". Something like if [ $HOST == user* ] then …

string bash comparison
How to iterate over arguments in a Bash script

I have a complex command that I'd like to make a shell/bash script of. I can write it in …

bash command-line
How to run .sh on Windows Command Prompt?

How can I run .sh on Windows 7 Command Prompt? I always get this error when I try to run this …

windows bash command-line sh
Why do you need to put #!/bin/bash at the beginning of a script file?

I have made Bash scripts before and they all ran fine without #!/bin/bash at the beginning. What's the point …

linux bash scripting shebang
How to obtain the number of CPUs/cores in Linux from the command line?

I have this script, but I do not know how to get the last element in the printout: cat /proc/…

linux bash cpu
How do I edit $PATH (.bash_profile) on OSX?

I am trying to edit an entry to PATH, as I did something wrong. I am using Mac OS X 10.10.3 …

bash macos terminal path osx-yosemite