Sponsored Content
Top Forums Shell Programming and Scripting Shell script command line arguments Post 302481877 by radoulov on Monday 20th of December 2010 06:01:48 AM
Old 12-20-2010
Quote:
Originally Posted by Deepak Dutt
thanks for answer i am known to this and yes, it varies for different shells

i have a doubt in

though my present shell is /bin/tcsh and if i run a script with

./script_name

the output is different than

tcsh script_name

?
I believe I understand why this is happening, it's should be specific to [t]csh and I suppose documented somewhere Smilie
On some (or all?) systems (Solaris included) when you invoke a script with no shebang as ./script_name from within [t]csh the script is executed by a predefined interpreter (/usr/bin/sh on Solaris):

Code:
> uname -sr ; echo $version
SunOS 5.8
tcsh 6.11.00 (Astron) 2001-09-02 (sparc-sun-solaris) options 8b,nls,dl,al,rh,color
> cat command_arg.sh
echo '----->' `ps -p$$ -oargs=`
echo "first arg passed is $1"
echo "2nd arg passed is $2"
echo "3rd arg passed is $3"
echo "4th arg passed is $4"
echo "5th arg passed is $5"
echo "6th arg passed is $6"
echo "7th arg passed is $7"
echo "8th arg passed is $8"
echo "9th arg passed is $9"
echo "10th arg passed is $10"
echo "11th arg passed is $11"
> ./command_arg.sh 11 12 13 14 15 16 17 18 19 20 21
-----> /bin/sh ./command_arg.sh 11 12 13 14 15 16 17 18 19 20 21
first arg passed is 11
2nd arg passed is 12
3rd arg passed is 13
4th arg passed is 14
5th arg passed is 15
6th arg passed is 16
7th arg passed is 17
8th arg passed is 18
9th arg passed is 19
10th arg passed is 110
11th arg passed is 111

So given the following script:

Code:
$ cat s
ps -p$$ -oargs=

We have:

Code:
$ bash -c './s'
bash -c ./s
$ ksh -c './s'
ksh -c ./s
$ tcsh -c './s'
/bin/sh ./s
$ csh -c './s'
/bin/sh ./s

Tested on Solaris e Linux.

Last edited by radoulov; 12-21-2010 at 04:33 AM.. Reason: Modified.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH script: piping passes command-line arguments

Dear forum I have the following small script: #!/bin/ksh echo -e "abba-o" | awk -F '-' '{ print $2 }' | cut -b 1It needs to be ksh.. in bash I don't have this problem. If I run this on opensuse 10.2 I get this as output: e If I run this on suse enterprise 10 sp2 then I get this: o ... (1 Reply)
Discussion started by: gemtry
1 Replies

2. Homework & Coursework Questions

I need to make a script that has 4 command line arguments to function properly.

I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies

3. Shell Programming and Scripting

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

4. UNIX for Advanced & Expert Users

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

5. UNIX for Dummies Questions & Answers

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (5 Replies)
Discussion started by: ajaira
5 Replies

6. Shell Programming and Scripting

How to use case and command line arguments in shell script?

Hi... can anyone please help me out in using the CASE and command line argument in shell script... i am bit new to shell scripting...below i have explained my proble with example... say i have an executable file with name 'new1.sh' and there are 3 functions in it a(), b() and c()....and there... (5 Replies)
Discussion started by: swap21783
5 Replies

7. Programming

How to pass the command line arguments to the shell script in c language?

hi, I am new in the shell script, and c programming with linux. I am looking to pass the arguments in c program that should be executed by the shell script. e.g. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { int i; for (i=1;i<argc; i++) { ... (2 Replies)
Discussion started by: sharlin
2 Replies

8. UNIX for Dummies Questions & Answers

Script to iterate all command line arguments

Hi guys, I am having trouble with this script. What i want it to do is to iterate all command line arguments in reverse order. The code below does this fine but i need the output to print the words on separate lines instead of one line: #!/bin/bash #Takes in the arguments and displays them... (7 Replies)
Discussion started by: pipeline2012
7 Replies

9. Shell Programming and Scripting

Parsing Command Line Arguments In C shell script

]I have a string like "/abc/cmind/def/pq/IC.2.4.6_main.64b/lnx86" and this string is given by user. But in this string instead of 64b user may passed 32 b an i need to parse this string and check wether its is 32b or 64 b and according to it i want to set appropriate flags. How will i do this... (11 Replies)
Discussion started by: codecatcher
11 Replies

10. Shell Programming and Scripting

Pass Arguments to Command from Shell Script

Hi all, I am working on a project, in which I have to connect to Bluetooth low energy device. I am able to connect and do data transfer from command line. But I want to do from script Here is my script #!/bin/bash #sudo hcitool -i hci0 lescan sleep 1 sudo hcitool -i hci0 lecc --random... (8 Replies)
Discussion started by: nithin@embdes
8 Replies
CPANPLUS::Shell(3)					User Contributed Perl Documentation					CPANPLUS::Shell(3)

NAME
CPANPLUS::Shell - base class for CPANPLUS shells SYNOPSIS
use CPANPLUS::Shell; # load the shell indicated by your # config -- defaults to # CPANPLUS::Shell::Default use CPANPLUS::Shell qw[Classic] # load CPANPLUS::Shell::Classic; my $ui = CPANPLUS::Shell->new(); my $name = $ui->which; # Find out what shell you loaded $ui->shell; # run the ui shell DESCRIPTION
This module is the generic loading (and base class) for all "CPANPLUS" shells. Through this module you can load any installed "CPANPLUS" shell. Just about all the functionality is provided by the shell that you have loaded, and not by this class (which merely functions as a generic loading class), so please consult the documentation of your shell of choice. BUG REPORTS
Please report bugs or other issues to <bug-cpanplus@rt.cpan.org<gt>. AUTHOR
This module by Jos Boumans <kane@cpan.org>. COPYRIGHT
The CPAN++ interface (of which this module is a part of) is copyright (c) 2001 - 2007, Jos Boumans <kane@cpan.org>. All rights reserved. This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. SEE ALSO
CPANPLUS::Shell::Default, CPANPLUS::Shell::Classic, cpanp perl v5.16.3 2013-05-20 CPANPLUS::Shell(3)
All times are GMT -4. The time now is 09:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy