default shell for the user


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers default shell for the user
# 8  
Old 01-15-2012
There is a lot of confusion and partial or plain wrong answers.

$0 is argv[0], the command given to start whatever shell or script you are currently running. The login process creates $0 (it becomes -bash for example). During login the getty code may define $SHELL (which is not always available in every type of shell).

That means when you first logon (using the above examples) $0 and $SHELL will match, sort of. When executing the script pandeesh wrote to test methods, running the script changed $0 for the duration of the script. Therefore, $0 is not reliable except when you are running in the login shell.

The SHELL variable is not changed by executing the shebang; exec looks up the magic word, like #!/bin/csh, from the first line of the script and executes the shell it points to
in order to run the script.

Next, /bin/sh is a special case. First off /bin is guaranteed to be available right when the system boots. So all boot up code depends on being able to run some shell. The shell is not specified by any standard, so /bin/sh has to be a symlink link or something called a POSIX-compliant shell. In the case of Solaris, /bin/sh is a POSIX-compliant Bourne shell. In Linux it is often a symlink to bash. Linux is not UNIX BTW. So /bin/sh may not always be POSIX-compliant.

Finally, as methyl said in another post to pandeesh - there is no one guaranteed single way to determine the shell, once it is running, in spite of all of the answers given above.

But. Best practices in shell scripting says: 'Always put a shebang at the top of the script, except in the case of a script meant to be sourced, ex: .profile'. Doing this solves most of the mysteries.

Any production environment that used all of the shells pandeesh looked for would be completely unmaintainable. Some shells like csh, should be avoided in spite of some deluded academic types who insist on teaching it.

Please stop posting more guaranteed ways to get the shell. There are none, just hacks that work sometimes, sometimes not.
This User Gave Thanks to jim mcnamara For This Post:
# 9  
Old 01-15-2012
Further to jim_macnamara and for further clarification.
The Shebang line only has special meaning if it is the very first line in a script. Anywhere else in the script and it is a just a comment line starting with a hash character.
Your test script therefore invoked /bin/bash then executed several identical "echo" statements.


If your homework today is about finding out what Shells are allowed on your system, there is system flat file containing a list of valid shells. This is referred to by commands that add or modify user accounts.
# 10  
Old 01-16-2012
Simply you can see the default shell of the user which you logged in :


Code:
#echo $SHELL


but if you want to see the current shell :

Code:
#echo $0

# 11  
Old 01-17-2012
Quote:
Originally Posted by methyl
If your homework today is about finding out what Shells are allowed on your system, there is system flat file containing a list of valid shells. This is referred to by commands that add or modify user accounts.
Can you explain this? Where we can find out the flat file?
# 12  
Old 01-17-2012
Oops. Did that from memory. The file /etc/shells is actually missing on many of my systems. The default values (when the file is missing) is in "man getusershell" , but this could well be different for Linux.
# 13  
Old 01-17-2012
$0 ---->represent program name
so when u write $0 in script it will always give your program name.
But when u write echo $0 on prompt it will give SHELL name which is also a program
# 14  
Old 01-17-2012
It's still worth looking at "man useradd" in some detail.
To see the defaults for a new user (including the default shell):
Code:
useradd -D

The behaviour of "useradd" can be altered with the parameter file:
Code:
/etc/default/useradd


Last edited by vbe; 01-17-2012 at 02:16 PM.. Reason: typo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

Change default shell of a specific user with awk

I would like to replicate the functionality of chsh (or passwd -e) by awk. This is what I got so far, but I think there should be an easier way to search and replace field $7 only for lines beginning with user_name: awk -v user_name="$user_name" -v new_shell="$new_shell" -F: '$1 == user_name {... (2 Replies)
Discussion started by: nomad84
2 Replies

4. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

5. UNIX for Dummies Questions & Answers

FTP user default shell defunct

Hello, I have a problem with my FTP users. I have create the ftp user on my AIX server, I set the default shell /bin/false or /usr/bin/false. Its enough that the user can logon via FTP. But when I try the user for example via ssh, the shell session is not killed, the session is defunct... (4 Replies)
Discussion started by: kalaso
4 Replies

6. UNIX for Dummies Questions & Answers

How to change Default Shell for any user?

Hi, I am new for solaris... how can we change default shell for any user and how to check that which shall currently we are in...... (1 Reply)
Discussion started by: lalit21984
1 Replies

7. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh URL="www.google.com" VBURL="10.5.2.211" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

8. Virtualization and Cloud Computing

Cloud User Shell 1.0 (Default branch)

http://c.fsdn.com/fm/screenshots/70112_thumb.png Cloud User Shell (cush) is a multi-call executable bringing RESTful cloud control to the command line, combining many useful cloud computing utilities into a single executable. It follows the Unix philosophy of writing components that work together,... (0 Replies)
Discussion started by: Linux Bot
0 Replies

9. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by default...so i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

10. Shell Programming and Scripting

New z-shell user

Hi, I've just downloaded the following files and have been tinkering with using zsh on my NT box. Z-shell executable: ftp://ftp.blarg.net/users/amol/zsh/zsh.exe.gz Unix Utilities: http://homepage.mac.com/shadowboxer/unxutils.exe First impressions are good but I have 2 questions.... (0 Replies)
Discussion started by: Damian Ibbotson
0 Replies
Login or Register to Ask a Question