LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2015, 10:29 AM   #1
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Rep: Reputation: 26
shell scripting question


in the /etc/passwd file for my user account I am set to tcsh.
so at the prompt if i do echo $SHELL i get /bin/tcsh.... obviously.

if i write a script that is:
#/bin/bash
echo $SHELL

it still responds with /bin/tcsh

is that normal?
is that a security feature?
what am i missing?
thanks.
 
Old 06-30-2015, 10:47 AM   #2
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
It is perfectly normal. The correct way to write te first line is actually
Code:
#! /bin/bash
However, that still would not alter what was actually taking place here. All you would be doing is creating a script, telling the script to execute within the BASH shell, and then read your environment variable of $SHELL, which is STILL tcsh.

If you want to write a shell script that CHANGED your SHELL for the current terminal session ONLY, it would be:

Code:
#! /bin/bash

export SHELL=/bin/bash
Once you closed the terminal session you were in when this script was ran (or in any other terminal that you opened), your default SHELL will still be tcsh. If you want to alter your login shell to BASH, you need to edit the /etc/passwd file or change your .profile in your home directory to designate the change.
 
1 members found this post helpful.
Old 06-30-2015, 11:53 AM   #3
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Original Poster
Rep: Reputation: 26
typo on my part missing the ! on the #/bin/bash when posting.

what i was overlooking was the echo $SHELL was being referenced from the user environment, not within the script.
thanks.
 
Old 07-01-2015, 02:50 PM   #4
cfajohnson
LQ Newbie
 
Registered: Aug 2012
Distribution: Linux Mint 17
Posts: 22

Rep: Reputation: Disabled
The $SHELL variable only contains your default shell.

Running this script will not change the value of SHELL:

Code:
#! /bin/bash

export SHELL=/bin/bash
...unless you source it, in which case the shebang line is meaningless.
 
  


Reply



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
I have a shell scripting question bartock Linux - General 5 03-06-2008 02:46 PM
shell scripting question creolophus Linux - Software 1 10-02-2006 02:13 AM
a shell-scripting question: mrchaos Slackware 3 09-22-2005 11:00 AM
Shell Scripting Question b_vasu Linux - Newbie 1 11-21-2003 02:10 PM
Shell Scripting Question chrisk5527 Linux - General 12 07-09-2003 03:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:58 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration