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.
keepnig the .sh extension is good practice but not a necessity. Even if you name a bash script without the .sh extension, it will work. You would need to assign execute perms for that file. Another way to run these files is
In linux the extension of a file is unimportant. The first line of the bash script will contain the line:
#!/bin/sh
or
#!/bin/bash.
What is important is that the executable bit is set. If you write your own script you need to use the 'chmod' command to allow it to be executed. For example: 'chmod u+x' allows the owner of the script to execute it but not anyone else. 'chmod a+x' enables execution by anybody. Of course you also need to set the 'r' read permission bit. i.e. 'chmod a+rx'
Also to be able to run a script, it needs to be located in one of the directories listed in your PATH environment variable. Or you need to include the pathname with the command.
Linux by default takes the precaution of not including the current directory in the path. To execute a file in the current directory precede the name with './' .
Like this:
./nameofscript.sh
You may have a bin directory in your home directory that is included in your path. This is a good place to copy scripts that you write yourself.
chmod u+x myscript
cp myscript ~/bin/
To learn the basic commands in linux, and how permissions work, a good place is the info page for coreutils. Try entering 'info:coreutils' or 'man:coreutils' in the konqueror browser (or in the application launcher). This is a convenient way to look at man and info pages.
can either one of you or anyone else in the linux community recommend a good bash script book or online tutorial?
I'm using Linux in a nutshell, and it isn't to detailed.
for instance i have been unable to find were it talks about using.
If the program is a file beginning with #!, the remainder of the first
line specifies an interpreter for the program. The shell executes the
specified interpreter on operating systems that do not handle this exe-
cutable format themselves. The arguments to the interpreter consist of
a single optional argument following the interpreter name on the first
line of the program, followed by the name of the program, followed by
the command arguments, if any
jschiwal,
Thanks for the site. http://www.tldp.org/LDP/abs/html/
That is exactly what I needed.
I was trying to find something like that on that site,
but was unable to find it.
In C you could use the system lib call eg:
system("/usr/bin/myscript.sh");
I assume C++ has a similar facility.
NB: always a good idea to specify the full path to avoid being hijacked....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.