test script to identify SHELL

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting test script to identify SHELL
# 8  
Old 08-26-2009

Why do you need to know what shell it is?

It is better to test for the features you want.

You can check for variables $BASH_VERSION and $KSH_VERSION (the latter only in pdksh).
# 9  
Old 08-26-2009

echo "myShell->[`ps -o 'pid,comm' -p "${pid}" | nawk 'FNR==2{print $2}'`]"

YMMV - not generic

Last edited by vgersh99; 08-26-2009 at 01:30 PM..
# 10  
Old 08-26-2009

Using any standard version of ps (and no other external command) in any Bourne-type shell:

ps -o comm -p "$$" | { read; read comm; echo "$comm"; }

However, that doesn't necessarily tell you anything about the shell, particularly if it's sh.
# 11  
Old 08-26-2009
I don't think that $SHELL is the right variable to test. Anyway, on a point of syntax the "==" is not valid in "test" when it is not bash.
cfajohnson approach to find a suitable variable which is only set by that shell is better. Use "if [ -z "${SUITABLE_VARIABLE}" ] .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell Script to identify lines in file1 and write them to file2

Hi, I am running my pipeline and capturing all stout from multiple programs to a .txt file. I want to go into that .txt file and search for specific lines, and finally print those lines in a second .txt file. I can do this using grep, awk, or sed for each line, but have not been able to get... (2 Replies)
Discussion started by: hmortens
2 Replies

2. UNIX for Dummies Questions & Answers

Shell Script to test telnet connection using port

Hello, I need to test telnet connections using port number for few hosts. Could you please help me? Thanks !! (1 Reply)
Discussion started by: skhichi
1 Replies

3. Shell Programming and Scripting

Test shell script (PROBLEM)

Dears , kindly I wanna do test for one KSH script to know how is it working , the problem that I'm facing is whenever put "sh -x ./my_script.sh" the output seems very long & although I tried to to redirect it to files as it shown , but it failed :eek: :- sh -x ./my_script.sh >... (2 Replies)
Discussion started by: arm
2 Replies

4. Shell Programming and Scripting

Identify variables used in the shell script

Hi, Is there any simple way to get/identify the variables that are used in a file and print those variable names. If I have something like this in a file, /$var/temp_dir/${var2}${var3}.log I want to display the variables 'var', 'var2' and 'var3' from that file. I tried something like... (6 Replies)
Discussion started by: pvamsikr
6 Replies

5. UNIX for Dummies Questions & Answers

Test: argument expected error in shell script

Hi, I am trying to write a small script that validates if there exist files that start with a pattern in a given directory. Below is the piece of my script: #!/usr/bin/ksh BTFDIR=/opt/ships/temp if then echo 'found' else echo 'not found' fi When I run this... (2 Replies)
Discussion started by: snvniranjanrao
2 Replies

6. Shell Programming and Scripting

Help with connectivity test using shell script

I want to test connectivity between different servers with my server using information as IP and port only. I have Name,IP List and port in one file. Please help how i can test connectivity is successful or not? File format will be: Name1,,80 Name2,,8080 Output could be ... (1 Reply)
Discussion started by: poweroflinux
1 Replies

7. Shell Programming and Scripting

Shell script to identify the number of files and to append data

Hi I am having a question where I have to 1) Identify the number of files in a directory with a specific format and if the count is >1 we need to concatenate those two files into one file and remember that in the second file the header should not be copied. it should be form first file.... (4 Replies)
Discussion started by: pradkumar
4 Replies

8. Shell Programming and Scripting

-a test in shell script

I need clarification in -a test. If say, in test -a left expression is not present but the right expression is present, do the shell will consider the left expression true and evaluate the right expression? For example: if ] then rm -f ${file} fi Is this test condition... (7 Replies)
Discussion started by: jatanig
7 Replies

9. Shell Programming and Scripting

Test for shell interpreter at beginning of script

What would be the best way or method to determine or test for the shell interpreter at the beginning of a script in the event one shell is not available? If I use the following: #!/bin/bash and /bin/bash is not available, then use I'd like to use /bin/ksh if it is available. #!/bin/ksh (8 Replies)
Discussion started by: nck
8 Replies

10. Shell Programming and Scripting

need help with test condition in shell script

I'm new to scripting and I need help with a bourn shell script. What i'm trying to do is a test condition where "if the time is within 2 hours, it's true" and so on. The time is in the following format DATE=`/bin/date +"%Y%m%d%H%S"` for example, 20060907152000. So, what the script first... (9 Replies)
Discussion started by: pieman8080
9 Replies
Login or Register to Ask a Question