Import (include) a file in bash script
Use
source [file]
or use
. [file]
Call a function dynamically
create_repo_from_$TYPE $SRC_PATH $DEST_PATH
extglob
find . -name '*ettercap*' exec rm -rf "{}"\;
or
find . -name
'*ettercap*'
| xargs rm -rf
Note that this will work incorrectly if there are any filenames containing newlines or spaces. To deal with filenames containing newlines or spaces you should use instead:
find . -name
'*ettercap*'
-print0 | xargs -0 rm
$1
,$2
,$3
, … are the positional parameters."$@"
is an array-like construct of all positional parameters,{$1, $2, $3 ...}
."$*"
is the IFS expansion of all positional parameters,$1 $2 $3 ...
.$#
is the number of positional parameters.$-
current options set for the shell.$$
pid of the current shell (not subshell).$_
most recent parameter (or the abs path of the command to start the current shell immediately after startup).$IFS
is the (input) field separator.$?
is the most recent foreground pipeline exit status.$!
is the PID of the most recent background command.$0
is the name of the shell or shell script.buy.html
https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
Add strings to file
cat >> /etc/profile << EOF
export GENERATE_GEP_CODE=”$GENERATE_GEP_CODE”
export GENERATE_BLADE_CODE=”$GENERATE_BLADE_CODE”
export ENUX=”ENUX”
export BOND_HASH_POLICY=”$BOND_HASH_POLICY”
export SHELF_ENV=”$SHELF_ENV”
EOF
TODO
exec 1>stdout.log 2>stderr.log
Send string to stdin
Command read one line of string from stdin
zic -d ~/tmp - <<< "Zone UTC+1015 10:15 - UTC+10:15"
The -
is to read from stdin instead of file.
or read multiple lines of string
zic -d ~/tmp - << EOF Zone UTC+1015 10:15 - UTC+10:15 EOF
Some commands don’t need -
cat <<< "Hello" cat - <<< "Hello"
work the same
Or we can use echo
echo "Zone UTC+1015 10:15 - UTC+10:15" | zic -d ~/tmp -
Redirect from a command
diff <(ls /bin) <(ls /usr/bin)
Read lines from file
while read line do echo =$line= done < /boot/grub/grub.cfg
Read lines from stdout
ls -l /home | while read line; do echo "output: $line"; done
References
http://stackoverflow.com/questions/20307299/linux-why-cant-i-pipe-find-result-to-rm
http://stackoverflow.com/questions/6541109/send-string-to-stdin