I'm not a bash scriptor, so this is no doubt a very simple question.
I have a bash script throwing an error. It looks like this:
#!/bin/bash
for i in (cat /root/list.txt)
do
doSomething
done
The error is on the second line, related to the curly brackets. So it seems curly brackets shouldn't be here... in which case, what should line 2 look like?
The script is supposed to read each line out of /root/list.txt and then doSomething with this (I removed the actual command for this example.)
Thanks!
The “cat” command in Bash stands for “concatenate”. This command is very frequently used for viewing, creating, and appending files in Linux.
The “cat” command, followed by the file name, allows you to view the contents of any file in the Linux terminal. However, instead of performing this step to view the contents of a file, we can simply incorporate this step into our bash script to serve the same purpose.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
There are no Booleans in Bash. However, we can define the shell variable having value as 0 (“ False “) or 1 (“ True “) as per our needs.
Probably
for i in $(cat /root/list.txt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With