With “END” being just an example of any random string that must not appear in the commented section:
: << 'END'
sleep 1
END
Different options:
# option 1, without variable for x in a b c; do echo $x; done # option 2, with string list="a b c" for x in $list; do echo $x; done # only works with sh and bash for x in ${=list}; do echo $x; done # only works with zsh for x in $(echo $list}; do echo $x; done # works with any shell # option 3, with an array list=(a b c) for x in $list; do echo $x; done
Use find
, with {}
being the file name:
find . -type f -exec <command> {} \; find -iname "<pattern>" -exec <command> {} \;
Manual solution:
#!/bin/sh function search_dir() { DIR=$1; for file in $DIR/*; do if [[ -f $file ]]; then echo "Do something with $file" fi; done for element in $DIR/* ; do if [[ -e $element && -d $element && \ $(basename "$element") != ".." && \ $(basename "$element") != "." ]]; then search_dir "$element"; fi; done; } search_dir "."
${<variable>:-<default-value>}
BASEDIR=$(dirname "$0")
echo "foo" 1>&2
date
): sed -r "s/([0-9]{4})-([0-9]{2})-([0-9]{2})_([0-9]{2})-([0-9]{2})-([0-9]{2})/\1-\2\-3T\4:\5:\6/"
readlink <symbolic-link>
var=`cat file` var=$(cat file)
zsh
also supports floating-point operations):echo $((2*3))
time (cat file1 > file2) time (cat file1 > /dev/null; sync)
if [[ $# -lt 2 ]]; then echo "Usage: foo.sh <arg1> <arg2>" 1>&2 exit 1 fi
diff <(grep x file1) <(grep y file2)