LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 10-08-2008, 05:12 AM   #1
s_b
LQ Newbie
 
Registered: Oct 2008
Posts: 17

Rep: Reputation: 0
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
 
Old 10-08-2008, 05:26 AM   #2
TwinReverb
Member
 
Registered: Sep 2008
Location: Misawa AB, Japan
Distribution: Slackware
Posts: 191
Blog Entries: 2

Rep: Reputation: 40
Quote:
Originally Posted by s_b View Post
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
 
Old 10-08-2008, 05:31 AM   #3
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
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
 
Old 10-08-2008, 05:59 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by s_b View Post
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.
 
Old 10-08-2008, 08:07 AM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
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.
 
Old 10-08-2008, 08:46 AM   #6
linuxer8786
Member
 
Registered: Sep 2008
Posts: 43

Rep: Reputation: 15
Quote:
Originally Posted by s_b View Post
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.
 
Old 10-08-2008, 12:08 PM   #7
s_b
LQ Newbie
 
Registered: Oct 2008
Posts: 17

Original Poster
Rep: Reputation: 0
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.
 
Old 10-08-2008, 12:32 PM   #8
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
You have received some directions in this thread. Hope you found them useful.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
looking for help in writing a bash script onepostonly Linux - General 3 10-05-2008 06:42 PM
Help Me>> Need help in writing Bash script lamak_98 Programming 6 10-04-2007 10:44 AM
Writing a bash script. lebabyg Linux - General 2 03-31-2007 11:39 AM
Bash (help writing script) lebabyg Linux - General 7 07-04-2006 05:22 PM
writing bash script ankitgdit Programming 4 08-19-2003 06:47 AM


All times are GMT -5. The time now is 08:57 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration