Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-09-2007, 05:26 AM
|
#1
|
|
Member
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67
Rep:
|
trying to learn bash
I am reading a tutorial on bash and the first command i am trying (to set an environmental variable)
doesnt work!
I am typing the command into terminal -- is that right? terminal is bash right?
|
|
|
|
04-09-2007, 05:48 AM
|
#2
|
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707
|
you could maybe tell us what the command you're typing in actually is? we're not psychic.
and a terminal is NOT bah, they are very seperate things. think of a terminal emulator as a black rectangular box with a blinking cursor on it e.g. a car chassis. and bash as the code that actually listens to what you're typing e.g. a car engine. you can run may many different things instead of bash within a terminal, csh, ksh, ash, sh, or somethign that isn't even a shell at all.
|
|
|
|
04-09-2007, 06:11 AM
|
#3
|
|
Member
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301
Rep:
|
ok, what terminal are you using?
You can also type everything in a terminal, or create a shell script.
To set a variable, you do
variablename="the text of your choice"
And to display it:
echo $variablename
If you want to make a shell script, you have to create a file let's call it filename.sh, which would contain, for example, something like this:
Code:
#!/bin/bash
variablename="hello world"
echo $variablename
Then, in a normal terminal, make that file executable with
chmod 0755 filename.sh
and run it (in a terminal) with
./filename.sh
It should display "hello world"
If you want to learn more about shell scripting, you can check here http://rute.2038bug.com/node10.html....00000000000000
|
|
|
|
04-09-2007, 07:10 AM
|
#4
|
|
LQ Newbie
Registered: Mar 2007
Location: Barcelona
Distribution: CentOS
Posts: 11
Rep:
|
All you need is man bash(1) and a lot of motivation (aka patience+dedicated time).
|
|
|
|
04-09-2007, 10:23 AM
|
#5
|
|
Member
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67
Original Poster
Rep:
|
Thanks for your help. I think i'm beginning to understand now! i'm a complete newbie so its hard getting your head round shell scripting- terminals etc but i've sorted out that minor problem and i'll be delving into it over the next few weeks - its looks interesting  lol
|
|
|
|
04-09-2007, 09:57 PM
|
#6
|
|
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,797
|
If you do shell scripting, setting an environment variable does not work. As soon as you leave the script, you are back in the parent's environment, and all the variables in the child process (that is what you started your script in) are gone.
Is that your problem?
Did you read the document which is pointed to in my signature?
jlinkels
|
|
|
|
04-10-2007, 03:12 AM
|
#7
|
|
Member
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67
Original Poster
Rep:
|
Quote:
|
Originally Posted by jlinkels
If you do shell scripting, setting an environment variable does not work. As soon as you leave the script, you are back in the parent's environment, and all the variables in the child process (that is what you started your script in) are gone.
Is that your problem?
Did you read the document which is pointed to in my signature?
jlinkels
|
NO i hadnt even got as far as that then ! i was just trying the commands in the tutorial and wasn't sure that using terminal was the right place to do it. I found out that i was just being stupid and typing the $ first which the tutorial showed but didn't explain you shouldn't type it.
Just shows that when giving advice you need to make it Absolutely clear what you mean!! it's too easy to forget that you take a lot of 'obvious' things for granted!
Yes i did go to your link thanks! its a great site and have been using that to write a little script.
Can I ask you about chmod?
chmod 0755 myfile.sh alters the mode of the file to an executable right? ok i did that and it all worked but i like to know what is going on - did it compile a binary when i did that? do you know how that works?
|
|
|
|
04-10-2007, 04:23 AM
|
#8
|
|
Member
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301
Rep:
|
chmod 0755 simply changes permissions to make it executable. It gives it the permissions rwxr-xr-x.
Nothing is required to be compiled. When you run a script, bash takes it line by line and runs the appropriate programs. (or something like this)
To understand chmod, try "man chmod". You could also have typed in, for example, "chmod a+x myfile.sh", which means make the file executable (x) to everybody (a).
Check here if you want to learn more http://rute.2038bug.com/node17.html....00000000000000
|
|
|
|
04-10-2007, 05:20 AM
|
#9
|
|
Member
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67
Original Poster
Rep:
|
Thanks Mate!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:58 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|