Bash

From Notes

Jump to: navigation, search

Command line arguments to a script

Using find

Great tips from O'Reilly Developers Network

Classic TCP Connection from Bash

exec 3<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.1\n\n">&3
cat <&3

Tips

Use !$ to pass the previous argument to the next command:

ls /usr/local/nagios/libexec
cd !$


Using BASH variables within a loop can be difficult, here is how to properly escape the variable to prevent interpretation by the shell and allow interpretation by the command (egrep, awk, find, etc..):

for i in $(cat <filename)
do
  egrep '^'"${i}"
done

Common Errors

If you receive the following output when performing shell operations:

cannot stat `\033[00m<filename>.txt\033[00m': No such file or directory

Try passing the --color=never parameter to your ls command.

The most common time to get this type of output is when passing the output of ls or ll to awk or another utility.

for i in `ll --color=never | egrep ' 2004 '| awk '{print $9}'`; do cp $i <path>; done
Personal tools