home
|
pages
|
back
|
start
|
windows
|
SIP
|
pushover
|
esxi
|
linux-bash
|
linux-bash-fn
|
linux-bash-code
|
awk-sed
|
git
|
keepass
|
php
|
ipmi
|
openvpn
|
# multiline comment,use : ' to open and ' to close : ' This is a very neat comment in bash ' https://linuxize.com/post/bash-heredoc/ # write/add stuff to files # quoting the delimiter with single or double quotes disables all shell expansions 'EOF' # <<- operator strips leading tab characters (not spaces) from each line of the heredoc, including the closing delimiter cat << EOF > /tmp/yourfilehere These contents will be written to the file. This line is indented. EOF ssh -T user@host.com << EOF echo "Local working directory: $PWD" echo "Remote working directory: \$PWD" EOF # direct out # quoting "$VAR" preserves newlines # indentation (only TABs,no spaces) , use a dash after the less-thans like <<-'EOF' read -r -d '' VAR <<'EOF' abc'asdf" $(dont-execute-this) foo"bar"'' EOF echo "$VAR" ### counter i=$((i+1)) # script header #!/bin/bash version=yymmdd #shopt -s expand_aliases SCRIPT=$(readlink -f $0) SCRIPTNAME=$(basename $SCRIPT) SCRIPTDIR=$(dirname $(readlink -f $0)) BASEDIR=$(dirname $SCRIPTDIR) LOGDIR=$SCRIPTDIR/logs LOG=$SCRIPTDIR/log-$SCRIPTNAME.log ###### loops IFS=$'\n' # make newlines the only separator for j in $(cat ./file_wget_med) do echo "$j" done # Note: IFS needs to be reset to default! for loops split on any whitespace (space, tab, newline) by default; the easiest way to work on one line at a time is to use a while read loop instead, which splits on newlines: while read i; do echo "$i"; done < ./file_wget_med files=`find <subdir> -name '*'` while read -r fname; do echo $fname done <<< "$files" while read -r fname; do echo $fname done <<< "`find <subdir>`" cat ./file_wget_med | while read -r j do echo $j done