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.
1) The #! is call the she bang. It tells your shell what program to interpt the rest of the file with. If you don't specify a #! the default is /bin/sh
2) You can use pipes but in this case you should do this ...
Code:
if [ -e $filename ]; then
...
another way would of been to check the $? after executing a command like this ...
Code:
filename=junk
ls -al $filename > /dev/null
if [ $? == 0 ]
then
echo "file $filename exist"
fi
no need for grep there.
3) what scripting language is used with linux? too many to list but here's a short list
tcl, bash, csh, sh, perl, python
Last edited by SheldonPlankton; 07-28-2004 at 05:53 PM.
Hi Markelo,
May be the oldest scripting language in *nix is the Bourne shell. Its executable file was "sh". It has some limitations but it was ubiquitous. When computers gained more power, the others started to appear like as "csh" which has a C like syntax, ksh (Korn shell) which maintains the Bourne shell syntax but has new commands and structures and, bash which is an acronym for "Bourne again shell". You can set up your profile to open your console always with one of these. The default for linux is bash. This setup is defined in "/etc/password", where the last field determines the user shell. Perl, python and tcl are powerful scripting languages, but normally not used at the console prompt.
Just to clarify (for clarity's sake), bash uses its own internal language for scripting. It does not (to my knowledge) require perl or any other scripting engine; it is a stand-alone interpreter.
Originally posted by Dark_Helmet Just to clarify (for clarity's sake), bash uses its own internal language for scripting. It does not (to my knowledge) require perl or any other scripting engine; it is a stand-alone interpreter.
OK. What I meaned was that does it works like a perl interpreter and thus would follow perl grammer or is it different language by itself.
For another matter I would still like to know how I can pipe something to grep witin my scripts. That ls -al | grep filename was just an example.
Ok in truth I was trying to do
lsmod | grep fglrx
You can give help in that also, but please help me with pipe.
When if-grepping, there's often no need for the '[' and ']'.
Just do:
Code:
if lsmod | grep fglrx >/dev/null ; then
echo "fglrx module is loaded."
else
echo "fglrx module is NOT loaded."
fi
"Grep" is the last command in the pipe-line, and as such it provides an exit code for the "if" to use as a condition. When grep finds the string it exits with zero code . If it does not find it, with non-zero exit code. That's all "if" needs.
Originally posted by markelo OK. What I meaned was that does it works like a perl interpreter and thus would follow perl grammer or is it different language by itself.
That's what I was trying to say: bash uses an internal, stand-alone interpreter. In that respect, it follows its own grammar, syntax, etc.
Quote:
Originally posted by markelo For another matter I would still like to know how I can pipe something to grep witin my scripts. That ls -al | grep filename was just an example.
Yes, you can use pipes as much as you like within backticks ( ` ). You can pipe one command into another, or have a string of 5 pipes, 10 pipes, or more.
You can use backticks in if statements like your original post, or you can assign it to a variable:
The two code snippets above are equivalent. Hko's code is also equivalent. He's directly using the return result of grep, whereas the code above is explicitly testing for grep's failing output (an empty string).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.