Not able to pass string with spaces in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to pass string with spaces in shell
# 8  
Old 03-23-2010
please find the attached files

It will create new file "runx"

I want to see the result at line number 211 in run file:
main file to edit "run": *include idemo.axe;btxt=demotxt

i want to change demotxt to "Power Tools or Accessories" and again I have few more things to pass,

after this I am using file run.do which will update run file as runx with the help of file source where i am passing all the parameters

Please let me know if you need anything else...
# 9  
Old 03-29-2010
Need help

Quote:
Originally Posted by patilrakesh1984
It will create new file "runx"

Hi Friends, I have attached the required files last week here, please let me know if you have found any solution it's really argent now

Thanks & Regards,
Rakesh Patil
patilrakesh1984@gmail.com


I want to see the result at line number 211 in run file:
main file to edit "run": *include idemo.axe;btxt=demotxt

i want to change demotxt to "Power Tools or Accessories" and again I have few more things to pass,

after this I am using file run.do which will update run file as runx with the help of file source where i am passing all the parameters

Please let me know if you need anything else...
# 10  
Old 03-29-2010
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
# 11  
Old 03-29-2010
Quote:
sed 's/brdtxt/'$3'/g'
The problem throughout this thread is the single quote characters. You cannot nest single quote characters. They are treated in pairs. In fact the middle two single quotes are not required in any of the sed commands posted.

sed 's/brdtxt/'$3'/g'
Thus the substitition parameter $3 is left outside of the scope of either pair of quotes. It sort of works until there are space characters in $3 - then the sed command errors.

Code:
Consider these simplified examples:

echo "brdtxt"|sed 's/brdtxt/'Banana'/g'
Banana

echo "brdtxt"|sed 's/brdtxt/'Power Tools or Accessories'/g'
sed: Function s/brdtxt/Power cannot be parsed.


Now we remove the middle two single quote characters and it starts working.

echo "brdtxt"|sed 's/brdtxt/Power Tools or Accessories/g'
Power Tools or Accessories

echo "brdtxt"|sed 's/brdtxt/"Power Tools or Accessories"/g'
"Power Tools or Accessories"

# 12  
Old 03-29-2010
Hi and sorry

Thnaks for letting me know the system present at your end, I will keep this in mind from next time.

---------- Post updated at 08:04 PM ---------- Previous update was at 07:59 PM ----------

Thanks Methyl! But I want to pass about 50 brand text in this file and hence was trying to pass them from outside, if it is not posible to pass a sentence with SHELL then I will have to use the method you have suggested but it really will not shorten the script which i want to.

Thanks & Regards,
Rakesh Patil
<email address removed>

Quote:
Originally Posted by methyl
The problem throughout this thread is the single quote characters. You cannot nest single quote characters. They are treated in pairs. In fact the middle two single quotes are not required in any of the sed commands posted.

sed 's/brdtxt/'$3'/g'
Thus the substitition parameter $3 is left outside of the scope of either pair of quotes. It sort of works until there are space characters in $3 - then the sed command errors.

Code:
Consider these simplified examples:

echo "brdtxt"|sed 's/brdtxt/'Banana'/g'
Banana

echo "brdtxt"|sed 's/brdtxt/'Power Tools or Accessories'/g'
sed: Function s/brdtxt/Power cannot be parsed.


Now we remove the middle two single quote characters and it starts working.

echo "brdtxt"|sed 's/brdtxt/Power Tools or Accessories/g'
Power Tools or Accessories

echo "brdtxt"|sed 's/brdtxt/"Power Tools or Accessories"/g'
"Power Tools or Accessories"


Last edited by vgersh99; 03-29-2010 at 12:10 PM.. Reason: email addressed removed
# 13  
Old 03-29-2010
That was only an example to justify removing the inner pair of single quotes.
However once we are inside a shell script we need to lose the single quotes completely or they will stop the substitution of $3.

Code:
sed 's/brdtxt/'$3'/g'
Change to:
sed -e "s/brdtxt/$3/g"


Obviously the same error is in all the "sed" statements but it only goes wrong of the parameter contains space characters.
# 14  
Old 03-29-2010
Thanks You Very much!

Thanks Methyl, it's now working, thanks very much! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass a variable string in To_Date Oracle function in shell script

Hello, I am trying to execute an SQL query from shell script. A part of script is something like this: fromDate=`echo $(date +"%F%T") | sed "s/-//g" | sed "s/://g"` $ORACLE_HOME/sqlplus -s /nolog <<EOD1 connect $COSDBUID/$COSDBPWD@$COSDBSID spool... (4 Replies)
Discussion started by: sanketpatel.86
4 Replies

2. Shell Programming and Scripting

Bash- Command run from script does not pass full parameters with spaces inside

There's a JavaScript file that I call from command line (there's a framework) like so: ./RunDiag.js param1:'string one here' param2:'string two here' I have a shell script where I invoke the above command. I can run it in a script as simple as this #!/bin/bash stuff="./RunDiag.js... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

3. Shell Programming and Scripting

How to pass variable with spaces from shell to expect?

I need call expect script from shell script and pass values some of which could contain space. How to make expect to treat such values as one variable? (1 Reply)
Discussion started by: urello
1 Replies

4. Shell Programming and Scripting

Pass string arg from shell to perl

My shell script generates a bunch of lines of text and passes this text as an argument to a perl script. I'm able to do this, but for some reason newlines don't get recognized in the perl script and so the script just prints actual '\n' instead of carriage returning, otherwise everything gets... (3 Replies)
Discussion started by: stevensw
3 Replies

5. Shell Programming and Scripting

Pass a string with spaces to a shell script

I'm a beginner and wasn't able to google my problem... I would like to pass a string with spaces to a shell script. my test_shell: #!/bin/sh -vx ####################################################### # generate_documentation (c) Ch.Affolter Nov. 2009 Version 1.0 #... (3 Replies)
Discussion started by: vivelafete
3 Replies

6. Shell Programming and Scripting

Pass string from shell script to java

Hi, I,m writing a program in shell script and currently this script is calling a java program. I have a problem to pass string variable from my shell script to the java program. I don't know on how to pass it and how the java program can call what I have pass from the shell script. This is... (3 Replies)
Discussion started by: badbunny9316
3 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. Shell Programming and Scripting

how can i pass parameter with spaces to csh script

Hello all i need to pass to my shell script parameter that looks like "2 3 3" inside the script i need to use this string that looks like this "2 3 3" but when i try to print the script im getting syntax error , this is my script : set s = $1 echo $s (1 Reply)
Discussion started by: umen
1 Replies

9. UNIX for Advanced & Expert Users

Please Help!! Reading a string of text with concurrent spaces into a shell variable

Please Help!! Here is a very simplistic example of what I am trying to accomplish. I need what I have inbetween the quotes to be read into the shell variable. x="This is fun" echo $x The results of x from the above expression is: This is fun Notice the unix takes out the... (1 Reply)
Discussion started by: mjs3221
1 Replies

10. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies
Login or Register to Ask a Question