Which shell can I use on Linux?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Which shell can I use on Linux?
# 8  
Old 06-27-2017
Of course it doesn't print anything as you didn't tell it to print anything. Do you know about the $SHELL variable?
# 9  
Old 06-27-2017
Also echo is not a awk action statement you are probably after print:

Code:
$ ps -hp $$ | awk '{ echo $5 }'
$ ps -hp $$ | awk '{ print $5 }'
-bash

# 10  
Old 06-28-2017
Quote:
Originally Posted by RudiC
Then ask your admin to install the ksh- rpm.
Is it really necessary to be admin, i.e. is there a disadvantage (for instance, some features not working) if one installs shells locally? At least with other programming languages (Perl, Ruby, Python, ...), if I'm on a centrally administered system where I don't have admin rights, I prefer to install them in my $HOME instead of requesting an admin to do this just for me, because I can then easier control the version I'm using etc.

Are there features in shells, which would cause trouble with this approach? I'm aware that if I'm not admin, I can't put any shell-specific startup file into /etc, but I would see it only as a minor issue.
# 11  
Old 06-28-2017
the script below:
Code:
 #!/bin/ksh
  
 NAME=`basename $0 .sh`
Today=`date '+%Y%m%d'`
TIMESTAMP=`date +%H:%M:%S`
LOCAL_SERVER=`hostname`
 let countcla=0
 countcla=`expr ${countcla} + 1`
 echo "${NAME} ${Today} ${TIMESTAMP} ${LOCAL_SERVER} ${countcla}"
MYSHELL=$(ps -hp $$|awk '{print $5}')
echo "MYSHELL IS ${MYSHELL}"
MYSHELL=`ps -hp $$|awk '{print $5}'`
echo "MY NEW SHELL IS ${MYSHELL}"
exit

Doesn't matter what I put in the first line
Code:
#!/bin/ksh

or
Code:
#!/bin/bash

both are working. The different is only if
Code:
 #!/bin/bash

result is
Code:
 test 20170628 08:58:12 gbdted01.us.db.com 1
MYSHELL IS /bin/bash
MY NEW SHELL IS /bin/bash

if I make
Code:
 #!/bin/ksh

the result is
Code:
 test 20170628 08:58:56 gbdted01.us.db.com 1
MYSHELL IS /bin/ksh
MY NEW SHELL IS /bin/ksh

So, my question is: what do I have installed Korn shell or bash? Obviously, I don't have to change old shell scripts, they will work. However, what will be working better, faster and code easier, ksh or bash?
That is what I have to tell to my manager. If bash easy to code and work faster, then we can request to install bash rpm.

What would you propose?

Thanks for contribution
# 12  
Old 06-28-2017
You have obviously both shells installed, and your code happens to be compatible to both (bash and ksh share a common language subset). Looking at your code, I guess it would also work with Zsh and Posix shell and even csh (but who wants to program in csh anyway). I don't know much about speed issues: Do you plan to write shell scripts which don't do much I/O, but mainly in-memory processing? If you are absolutely free to choose the shell, select the one which you like best. For instance, I consider Zsh most powerful and convenient from the programmer's point of view, but I know also programmers who say the same about bash or ksh.

Note also that you have to take account the version of the respective shell, because features change between versions. I would prefer working with a very recent bash over a very old Zsh....
# 13  
Old 06-28-2017
As rovf says, you seem to have either installed.
Please be aware that your script will be executed in a subshell invoked with the interpreter named in the shebang (the very first line in the script if starting with EXACTLY #! - no space allowed as opposed to what you have in your example). So that doesn't say anything about your login shell. Try a simple echo $0 at the command prompt to see what that would be.
# 14  
Old 06-28-2017
rovf, all our scripts are using I/O, we are reading files or getting data from database and cerate reports, some - small, some - huge.

RudiC
Code:
 echo $0

gives me
Code:
-ksh

If we have bash installed, I would go with bash, but it depends of big boss.
But what is you advise, which I can send to my manager use bash or use ksh? Of course the problem will get into "money" issue. If we have to change all scripts to bash, then I don't know if budget allows company to do it. Anyway, I need your advise what to tell my manager to persuade him to go with bash

Thanks for contribution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash Shell Linux

I have a csv file that looks like this Name,Food,Sport James,Curry,Gym Darren,Pizza,Football Jim,Fish,Hockey James,Sushi,Tennis My code looks like this IFS="," sed 1d $file_name | while read Name Food Sport do mkdir -p $Name #echo "==================" #echo "Name: $Name" (3 Replies)
Discussion started by: darklord173
3 Replies

2. UNIX for Dummies Questions & Answers

Need some Help please with Linux shell script.

we need help with the syntax with this shell script, if you could create this shell script we can donate to a charity etc. we need to set up a directory called user3 inside directory user3 we need to create the following files : afile, anyfile, anotherfile, afiletest, bfile. bfiletest, cfile,... (3 Replies)
Discussion started by: cometboy
3 Replies

3. UNIX Desktop Questions & Answers

Help with Linux shell

Taking a class and having trouble with this whole section. 1. What is the name of the action the shell performs on your command-line after you hit the ENTER key (i.e., to cut your command-line syntax into its constituent tokens, including its commands, options and arguments)? Hint: It is a... (1 Reply)
Discussion started by: red20132014
1 Replies

4. Shell Programming and Scripting

Script Shell Linux

Hello, Please, how can I complete this script: Thank you (2 Replies)
Discussion started by: chercheur857
2 Replies

5. Homework & Coursework Questions

Linux Shell Script

Hi Guys I am new to Linux Shell Scripting . Can any one help me with this Task...files are attached for reference Task 1: write a script to generate a large size report file MX0002_new.XML by using the template MX0001_new.XML. Shell script is recomended, and it can run on Linux without... (2 Replies)
Discussion started by: samy_1811
2 Replies

6. Shell Programming and Scripting

Need help! Linux shell script

Hi all, I am trying to make a Nodemanager work in RHEL 5 I got this script from 'oraclemiddleware.wordpress.com', and made appropriate changes to suit my weblogic installation. I keep getting the error, "line 82: syntax error: unexpected end of file". I have checked every line to make sure all... (4 Replies)
Discussion started by: chakrv1
4 Replies

7. Shell Programming and Scripting

Shell programming in Linux

Hi, I have been working on Sun Solaris since a long time. Recently I got to work on RH Linux. My Linux version details are: Linux 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux I have a simple command in my shell script: export BKPTAG=`date... (3 Replies)
Discussion started by: sagarparadkar
3 Replies

8. Shell Programming and Scripting

Shell Scripting Linux

In shell Can I pass " to a program ? If not what is the work around ..? Can I define * as a wild card charecter that will return all the values from the files ..? I am trying to create a tool that will return the values from a property file . This tool has to support all the wild card... (1 Reply)
Discussion started by: app1sxv
1 Replies

9. Shell Programming and Scripting

help with linux shell script

HI im a novice with shell scripts but i need help with a random script I have this folder filled with 500 different file names... I need help creating a script that will take each filename and make a new folder named that filename and then move that file into the newly created folder. Then the... (1 Reply)
Discussion started by: emachala
1 Replies

10. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies
Login or Register to Ask a Question