read command line as it is


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read command line as it is
# 1  
Old 09-25-2008
read command line as it is

I want to read the command line as it is in the script.
say
prompt$ a.sh 'inst_cont_Header__dss -v '" 0"' -m'

i want to use 'inst_cont_Header__dss -v '" 0"' -m' as it is, inside the scripts a.sh.

I've tried
$@
"$@"
$*
"$*"

but all of these in some way or other tamper the sting in the command line - these remove " or ' or sqeeze multiple spaces into one.

Please help.
# 2  
Old 09-25-2008
on running - $ a.sh 'inst_cont_Header__dss -v '" 0"' -m'
required string - inst_cont_Header__dss -v '" 0"' -m
"$@" gives - inst_cont_Header__dss -v 0 -m

It removes ' or " from string .
# 3  
Old 09-25-2008
Try:

Code:
a.sh inst_cont_Header__dss -v "'"\" 0\""'" -m

You can echo the variable in your script with:
Code:
echo "$@"

Regards
# 4  
Old 09-25-2008
The problem is , this scripts have to generic ,, I' won't know what argument will be coming ..so won't able \ to escape..

Thanks for ur reply Frank!!

Is there any other way ...
# 5  
Old 09-25-2008
Quote:
Originally Posted by ajitkumar2
I want to read the command line as it is in the script.
say
prompt$ a.sh 'inst_cont_Header__dss -v '" 0"' -m'

What you have there is equivalent to:

Code:
inst_cont_Header__dss -v           0 -m

That is what the script sees.

If you want the shell to see something else, then it has to be written differently.
Quote:

i want to use 'inst_cont_Header__dss -v '" 0"' -m' as it is, inside the scripts a.sh.

I've tried
$@
"$@"
$*
"$*"

but all of these in some way or other tamper the sting in the command line - these remove " or ' or sqeeze multiple spaces into one.

If the variable is unquoted multiple spaces are (except in rare instances) just separating arguments; the number of spaces is irrelevant.
# 6  
Old 09-26-2008
Thanks for the reply.
But That is not the case
say i need to run the script OTP_Extract.sh that require some command line args eg -

$OTP_Extract.sh -v '" 0"' -m DAILY

-v is to passes " 0" to this. number of spaces around 0 are important.


But I need to run this by other script keeping all command OTP_Extract.sh and options -v '" 0"' -m DAILY in the command line args of other scritp ,say a.sh

I 'll use a.sh as -

$a.sh 'script and args'

and a.sh is like -

$cat a.sh
EXECUTE="$@"
ksh "${EXECUTE}"

The problem is that $@ doesn't pass 'script and args' properly if it have single quotes in between . I've tried escaping by back slash , but it doesn't work.
What I need is that If I echo $EXECUTE I shoud get -

OTP_Extract.sh -v '" 0"' -m DAILY


Please help.
# 7  
Old 09-26-2008
callenge to masters

say i need to run the script OTP_Extract.sh that require some command line args eg -

$OTP_Extract.sh -v '" 0"' -m DAILY

-v is to passes " 0" to this. number of spaces around 0 are important.


But I need to run this by other script keeping all command OTP_Extract.sh and options -v '" 0"' -m DAILY in the command line args of other scritp ,say a.sh

I 'll use a.sh as -

$a.sh 'script and args'

and a.sh is like -

$cat a.sh
EXECUTE="$@"
ksh "${EXECUTE}"

The problem is that $@ doesn't pass 'script and args' properly if it have single quotes in between . I've tried escaping by back slash , but it doesn't work.
What I need is that If I echo $EXECUTE I shoud get -

OTP_Extract.sh -v '" 0"' -m DAILY


Please help.
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 read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

Read line by line and execute command

Hi ALL, I have a requirement like this. 1.GET ALL TABLE NAME (just table name) keep in file 2.Read line by line and get the count of table from tablename files. tablename detail has a sql statement "db2 select tabname from syscat.tables" (1 Reply)
Discussion started by: netdbaind
1 Replies

3. Shell Programming and Scripting

Read command stop on either EOF or a specific line

I'm trying to stop reading a file until the end of the file is reached or a defined delimiter line is reached. Some how I need to test the fail state of the last 2 commands, not just the last command. echo -e "hello\ngoodbye\n####\ntesting" | while read line; ]; do echo "$line"; done hello... (4 Replies)
Discussion started by: Michael Stora
4 Replies

4. Shell Programming and Scripting

Error to Read Input from command line

Team , I am trying to write a case condition for database backups.But I am unable to make the script to read input from command line . while true ;do read -p "Do You Wish To Take Database Backup ?? " yn case $yn in *) echo " YES take backup ";; *) echo " NO BACKUP " ;; ... (9 Replies)
Discussion started by: rocking77
9 Replies

5. AIX

Bypass Read Line in profile through AIX command

Hi All, I have a complicated requirement where in I have a "root" user and a user named "xeadmin" I want to take sudo of "xeadmin" by command sudo su - xeadmin. Later i need to hit 2 enter keys as there are 2 read line commands inserted in profile of "xeadmin" and I reach command prompt, i need... (1 Reply)
Discussion started by: hiteshsathawane
1 Replies

6. Shell Programming and Scripting

Need help to read command line arguments?

I am new to schell scripting . My objective is to write a ksh shell script that performs following tasks: - 1. Script reads all command line arguments (arguments are file names) and checks if it contains charachters "abc" in it. 2. If it contains "abc" it will execute a binary file xyz <command... (3 Replies)
Discussion started by: acmilan
3 Replies

7. Shell Programming and Scripting

read line and run a different command according to the output

Hi. I'm trying to write a script that reads a line on a file and runs a different command for a different line output. For example, if it finds the word "Kuku" on the line it sends mail to Kuku@kuku.com. Otherwise, it sends mail to Lulu@lulu.com. TIA. (2 Replies)
Discussion started by: Doojek9
2 Replies

8. Shell Programming and Scripting

Multi Line 'While Read' command issue when using sh -c

Hi, I'm trying to run the following command using sh -c ie sh -c "while read EachLine do rm -f $EachLine ; done < file_list.lst;" It doesn't seem to do anything. When I run this at the command line, it does remove the files contained in the list so i know the command works ie... (4 Replies)
Discussion started by: chrispward
4 Replies

9. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

10. Programming

command line socket read utility

HI I have a messaging s/w daemon(TIBCO rvrd) provided by vendor which will accept connections from various clients and routes messages to the destinations. In order to route it internally uses two ports(one tcp adn one udp). I want to know on which port(tcp/udp) it is transmitting... (3 Replies)
Discussion started by: axes
3 Replies
Login or Register to Ask a Question