Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

bash nested for loop one line

# Basic syntax:
for i in a b; do for j in c d; do echo $i $j; done; done
# Where:
#	- each do statement has to end with a semicolon. *This is why there is
#		a semicolon after the first done
#	- multiple commands can be passed to each for loop, they just need to be
#		separated by semicolons
#	- for more complex for operations, sometimes it can be helpful to surround
#		the do statements with parentheses, e.g.:
#		for word in $(more words.txt); do (printf "$word
" & for file in $(ls *); do (grep $word $file -c); done;) done >> output.txt
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #bash #nested #loop #line
ADD COMMENT
Topic
Name
2+8 =