Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - for i in cat?

Tags:

linux

bash

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!

like image 541
Alasdair Avatar asked Apr 09 '12 04:04

Alasdair


People also ask

What is bash cat command?

The “cat” command in Bash stands for “concatenate”. This command is very frequently used for viewing, creating, and appending files in Linux.

Can I use cat in a bash script?

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.

What does [- Z $1 mean in bash?

$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.

Is it true 1 or 0 bash?

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.


1 Answers

Probably

for i in $(cat /root/list.txt)
like image 79
geekosaur Avatar answered Oct 22 '22 08:10

geekosaur