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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top