ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello everyone! I'm having a problem with this simple script...
ls -la /|awk '{print $8}'>list
while read line
do
if "$line"="boot"
then
echo "$line"
fi
done < list;
Can anyone help me? When I run it I get:
bash: =boot: command not found
bash: .=boot: command not found
bash: ..=boot: command not found
.
.
.
and all the way down untill the end ot the file...
you have to use square brackets to perform a numeric or string comparison. Without them the expression is interpreted as a command, hence the command not found error. Indeed you can also test for commands using if/then without brackets: it will evaluate the exit status of the command (success or failure), but this is another story.
Ok, the error is gone now, but the output is the content of the file (the whole content), not just boot...
Given the lines of code you have posted, that's not possible. Maybe the entire content of the file is displayed from a command you didn't show us. What is the actual code of your script?
I dont get any output with that (coz there's no 'boot' in the line)
Not really true, indeed. In bash you can use either = and == for string comparison. The problem was that the OP didn't put spaces around the = sign. This resulted in a whole and unique string which is always evaluated as true.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.