how to read argument with $ value in the word

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read argument with $ value in the word
# 1  
Old 09-16-2011
how to read argument with $ value in the word

i am having a shell script reading two arguments.
when the shell script is passed with argument containing $ in it, the value from $ onwards is getting truncated and my script is failing.
i have to do in reading the arguments in the shell script only as i am not having control on the arguments getting passed to the script

Kindly help me.

Code: arg$1 arg2

echo first argument: arg 
echo second argument: arg2


echo There are $# arguments to $0: $*    
echo first argument: $1    
echo second argument: $2

Kindly hep me in accepting the argument word containing "$" in it

Thanks in advance

Last edited by radoulov; 09-16-2011 at 10:41 AM.. Reason: Code tags!
# 2  
Old 09-16-2011
You cannot do anything if you have no control on the arguments:
your shell will try to interpret the unquoted special characters before your shell script actually sees them.
# 3  
Old 09-16-2011
what is the character to nullify the '$"
# 4  
Old 09-16-2011
You need to quote it using strong (single) quotes: 'arg$1' or escape it: arg\$1 before passing it to the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Read a json file passed as cmd line argument

usage: config.json config.json: { "HOST":"abc", "DB_NM":"xyz", "USR_NM":"asd", "PWD":"xxx", ......... ......... ......... ........ } (2 Replies)
Discussion started by: RGRT
2 Replies

2. Shell Programming and Scripting

Read contains within { and replace the word

Hello Team, I am looking for help to read contains from { } and replace the word. basically, I need to use this for nagios configuration file where each host/service define within {}. I want script or syntax to which read first word/line from {} and replace the desire word within that {}. ... (5 Replies)
Discussion started by: ghpradeep
5 Replies

3. Programming

C Code to read a word from file

Hello All, I have to write a C Code to read a word from file and Keep track of the number of word occurrence in each line and total in the file. Maintaining total count is easier but maintaining per line count is what I am struggling to achieve. I thought of maintaining linked list... (3 Replies)
Discussion started by: anand.shah
3 Replies

4. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

5. Shell Programming and Scripting

Read last word of the line.

Hi, I need a script to read last word of the line and out put in some temp file. i it can contain any word like: My name is Harry. or My zip code is 24490 or it can be My secret code is 024H I just need last word of the line (Harry, or 2440 or 024H) Thanks for the posts below.... (10 Replies)
Discussion started by: HarryReid
10 Replies

6. Shell Programming and Scripting

Read env variables from argument file

Hi, I have a generic shell script ( to read files (batchJob) with commands in them and execute the commands by reading the batchJob file as below ./ batchJob batchJob file $BATCHDIR/ $DATADIR/ $OTHER_ENV_VAR/ ... (10 Replies)
Discussion started by: bOngY
10 Replies

7. Shell Programming and Scripting

Read last word of nth line

Hi people; i want to read the last word of the 14th line of my file1.txt. Here is the EXACT 14th line of the file. 250 SectorPortnum=3,AuxPortInUngo=2,PortDeviceGroup=1,PortDeviceSet=1,PorDevice=1 20 >>> Set. i have to get the word Set. how can i call it and also how... (3 Replies)
Discussion started by: gc_sw
3 Replies

8. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

9. UNIX for Dummies Questions & Answers

Read last word of file name

Hi I am writing a script that needs to read all file from a directory and print only last word of all file names. My script: for file in /documents/files/ do $shortFile=$(file##.*) echo $shortFile done All my file names in /document/files/ directory are like unix_ubuntu but I need to... (1 Reply)
Discussion started by: watsup
1 Replies

10. Shell Programming and Scripting

how to read each word in a file

Hi, I want to read each word in a file. start at a particular character say '%' and read till another character say ')' (these two characters form the part of my file). then i want to delete the whole sentence(that is between '%' and ')' ) and keep the remaining file intact. Its urgent... (1 Reply)
Discussion started by: kaps_jhaver
1 Replies
Login or Register to Ask a Question