Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| 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. |
|
 |
10-08-2008, 05:12 AM
|
#1
|
|
LQ Newbie
Registered: Oct 2008
Posts: 17
Rep:
|
Writing a bash script
hi
I need to write a bash script that prints the values of the following data of
Example
My username : dalux
My homedirectory : /home/dalux
My hostname : localhost. localdomain
My current dir. : /home/dalux/courses
My shell : /bin/bash
My search path : /usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin
And all the data to the right of the colon shall be read read from the enviroment of my Linux box.
I have no idea how to do this. Can anyone help me? I need a complete explanation.
Thanks
|
|
|
|
10-08-2008, 05:26 AM
|
#2
|
|
Member
Registered: Sep 2008
Location: Misawa AB, Japan
Distribution: Slackware
Posts: 186
Rep:
|
Quote:
Originally Posted by s_b
hi
I need to write a bash script that prints the values of the following data of
Example
My username : dalux
My homedirectory : /home/dalux
My hostname : localhost. localdomain
My current dir. : /home/dalux/courses
My shell : /bin/bash
My search path : /usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin
And all the data to the right of the colon shall be read read from the enviroment of my Linux box.
I have no idea how to do this. Can anyone help me? I need a complete explanation.
Thanks
|
Code:
#!/bin/bash
# This program is designed to tell you what user you are currently:
whoami
# I'm assuming you only want to see what your /home area ("~") is:
# This should print the long-line, human readable version of your home:
ls -ldh ~
# This shows you your host name by reading the file that contains it:
cat /etc/HOSTNAME
# This shows your "present working directory", i.e. "where am i?"
pwd
# First, the stuff in the `` tells you what shell you are in
# Second, since you wanted it with the path, i used "which" for that.
# The "which" command shows you the full path of shell commands:
which `echo $0`
# This prints the environment variable $PATH, which is your command path.
echo $PATH
|
|
|
|
10-08-2008, 05:31 AM
|
#3
|
|
Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,592
|
I have a gut feeling this is homework, so forum rules say we should not solve it for you. Indeed it wouldn't be fair. But this is such a simple homework assignment, surely any basic bash tutorial will have the answers in the first few pages, try:
http://tldp.org/LDP/abs/html/
and probably this will help too:
http://rute.2038bug.com/index.html.gz
|
|
|
|
10-08-2008, 05:59 AM
|
#4
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,893
|
Quote:
Originally Posted by s_b
And all the data to the right of the colon shall be read read from the enviroment of my Linux box.
|
I think this is the relevant part of your homework: you have to become familiar with environment variables. The command set gives you them all. Anyway, as H_TeXMeX_H pointed out a good tutorial should give all the answers, as well as your course notes and your teacher. Try to search the answers deep inside this chapter of the Advanced Bash Scripting Guide.
|
|
|
|
10-08-2008, 08:07 AM
|
#5
|
|
Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,592
|
Yes, I guess that's the easiest solution, just type in 'set' (no quote) into the terminal, you should be able to figure out the rest on your own.
|
|
|
|
10-08-2008, 08:46 AM
|
#6
|
|
Member
Registered: Sep 2008
Posts: 43
Rep:
|
Quote:
Originally Posted by s_b
hi
I need to write a bash script that prints the values of the following data of
Example
My username : dalux
My homedirectory : /home/dalux
My hostname : localhost. localdomain
My current dir. : /home/dalux/courses
My shell : /bin/bash
My search path : /usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin
And all the data to the right of the colon shall be read read from the enviroment of my Linux box.
I have no idea how to do this. Can anyone help me? I need a complete explanation.
Thanks
|
I think you should complte your homework by yourself, Mr Google is enough for you.
you could get good guide in here:
http://www.freeos.com/guides/lsst/
Last edited by Tinkster; 10-30-2010 at 03:44 PM.
|
|
|
|
10-08-2008, 12:08 PM
|
#7
|
|
LQ Newbie
Registered: Oct 2008
Posts: 17
Original Poster
Rep:
|
It WAS my homework but I failed, and now I just wanted to know how to do proceed.
Last edited by s_b; 10-08-2008 at 12:10 PM.
|
|
|
|
10-08-2008, 12:32 PM
|
#8
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,893
|
You have received some directions in this thread. Hope you found them useful.
|
|
|
|
| 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 02:16 PM.
|
|
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
|
|