Shell script, Ubuntu question

holy_spirit

New Member
Reaction score
25
I'm a bit new to Ubuntu OS and especially Shell script
I want to know my various system configurations using shell script, so how can I know the following :
• current shell
• home directory
• operating system name, network nodename , operating system release
• current path setting
• current working directory
• Show all available shells

Thanks in advance.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
I'm a bit new to Ubuntu OS and especially Shell script
I want to know my various system configurations using shell script, so how can I know the following :
• current shell
• home directory
• operating system name, network nodename , operating system release
• current path setting
• current working directory
• Show all available shells

Thanks in advance.
current shell:
$echo $0
or perhaps use ps.

home directory:
$echo ~

operating system name, network nodename , operating system release :
Kinda depends on what you mean with "operating system". If you're talking about different distributions then I guess you just have to know it, or rely on some distribution specific tool go get the version you are using. I'm not entirely sure though.
If you mean what kernel version you have then
$uname -r
will do. (-n for node name)

current path setting:
echo $PATH
suppose it can be shell specific... I've no idea

current working directory:
$pwd

Show all available shells:
No idea.

Are these really your own questions? If so I predict that you'll be a linux hacker and the end of this year.
 

UndeadDragon

Super Moderator
Reaction score
447
Are these really your own questions? If so I predict that you'll be a linux hacker and the end of this year.

I was thinking that :rolleyes:
 

holy_spirit

New Member
Reaction score
25
Are these really your own questions? If so I predict that you'll be a linux hacker and the end of this year.
these are not mine , it's a several question for a linux RedHat OS i found in a doc file, and I interested in learning shell script
I like hacking, but never try it and that isn't the point of this questions, but if this will do that then no problem (j/k)

now I'm writing a myConfig.sh file to display all previous commands, and current shell command doesn't work, it supposed to display first parameter in sth -i guess- so it displayed my meConfig.sh path when i'm trying to execute that file through terminal

Quote:
Show all available shells:
No idea.
cat /etc/shells
needed through script
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
(assumed: bash)

• current shell
echo $SHELL

• home directory
echo $HOME

• operating system name, network nodename , operating system release
depending on what you call "operating system":
uname -on
uname -snr

If you want the distribution, just look for the usual suspects in /etc...

• current path setting
echo $PATH

• current working directory
echo $PWD

needed through script
Then store it in a variable (after cleaning up the comments in case there are some):
SHELLS=`cat /etc/shells`
 

holy_spirit

New Member
Reaction score
25
every thing went good, except (available shells)
here is my script
Code:
echo 'Currently logged user and his log name'
who i am
echo 'Your current shell'
echo $SHELL
echo 'Your home directory'
echo $HOME
echo 'Your operating system name, network nodename , operating system release '
uname -on
uname -snr
echo 'Your current path setting'
echo $PATH
echo 'Your current working directory'
pwd
echo 'Show currently logged number of useres'
who -q
[B][SIZE="3"]echo 'Show all available shells'
set shells= '/cat/etc/shells'
echo $shells[/SIZE][/B]
I guess I don't have that path, Or am I missing something ?

another question :
• Take as command-line options any number of text files
• Read in each of these files, converts all the letters to uppercase, and then stores the results in a file of the same name but with a .caps extension


I know how to pass params, and how to loop through them (how good am i..).
what is the syntax that allow me to read a file and apply uppercase method -if this available- to all read chars ?
Is this script support command like methods ?

By the way, I can't +rep you every time you answering me, I'll do that at the end.
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
Code:
echo 'Show all available shells'
set shells= '/cat/etc/shells'
echo $shells
I guess I don't have that path, Or am I missing something ?
Yes, you missed that yours is plain wrong. So, for the third time:
  • The file only contains a list of shells:
    SHELLS=`cat /etc/shells`
  • There are also comments in the file:
    SHELLS=`sed 's/#.*//' /etc/shells`

another question :
• Take as command-line options any number of text files
• Read in each of these files, converts all the letters to uppercase, and then stores the results in a file of the same name but with a .caps extension

Code:
#!/bin/bash

for file in $@; do
	sed 's/.*/\U&/' $file > $file.caps
done


What about doing your homework by yourself?
 

holy_spirit

New Member
Reaction score
25
Great, all work perfectly

can you explain this 's/.*/\U&/'

What about doing your homework by yourself?
I don't have any homeworks, as I said before, it's series of questions I'm trying to learn from

Question :
how can I read one line from a file, and get first litter from that line ? and how can i loop through all lines ?

for future, can you refer to some expert learning sites that can help in this field, so I can stop bothering people here.
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
can you explain this 's/.*/\U&/'

info sed
Code:
The `s' Command
===============

   The syntax of the `s' (as in substitute) command is
`s/REGEXP/REPLACEMENT/FLAGS'.  The `/' characters may be uniformly
replaced by any other single character within any given `s' command.
The `/' character (or whatever other character is used in its stead)
can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\'
character.

   The `s' command is probably the most important in `sed' and has a
lot of different options.  Its basic concept is simple: the `s' command
attempts to match the pattern space against the supplied REGEXP; if the
match is successful, then that portion of the pattern space which was
matched is replaced with REPLACEMENT.

   The REPLACEMENT can contain `\N' (N being a number from 1 to 9,
inclusive) references, which refer to the portion of the match which is
contained between the Nth `\(' and its matching `\)'.  Also, the
REPLACEMENT can contain unescaped `&' characters which reference the
whole matched portion of the pattern space.  Finally, as a GNU `sed'
extension, you can include a special sequence made of a backslash and
one of the letters `L', `l', `U', `u', or `E'.  The meaning is as
follows:

`\L'
     Turn the replacement to lowercase until a `\U' or `\E' is found,

`\l'
     Turn the next character to lowercase,

`\U'
     Turn the replacement to uppercase until a `\L' or `\E' is found,

`\u'
     Turn the next character to uppercase,

`\E'
     Stop case conversion started by `\L' or `\U'.


for future, can you refer to some expert learning sites that can help in this field, so I can stop bothering people here.
Easy: your distribution comes with the always helpful "man" and "info" commands.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top