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
# 1  
Old 03-22-2010
Not able to pass string with spaces in shell

I have to pass a sentence in a file, the specs are as:

Code:
cat run | sed 's/SRT/'$8'/g'  | sed 's/plength/68/g'  | sed 's/stcol/'$5'/g' | sed 's/encol/'$6'/g' | sed 's/brdtype/'$1'/g' | sed 's/brdtxt/'$3'/g' | sed 's/demotxt/Total '$2'/g' | sed 's/bantxt/ban_'$7'/g' | sed 's/validcodes/'$4'/g' > runx

Code:
TEXT = "Power Tools or Accessories"
source run.do POWERTOOLS "$TEXT" powertools 012:042 1242 4242 power1 nosort

Here at demotxt I have to pass a string "Power Tools or Accessories", but i am getting only blanks with this specs in the output file

Out put I am getting
Code:
*include idemo.axe;btxt=Total

and output desired is
Code:
*include idemo.axe;btxt=Total Power Tools or Accessories

Please help me out...

Last edited by pludi; 03-22-2010 at 03:57 PM.. Reason: code tags, please...
# 2  
Old 03-22-2010
Not very clear
what contains 'run' ?
what's 'run.do' ?
the sed line could be written whithout cat & pipe :
Code:
 sed -e 's/SRT/'$8'/g' -e 's/plength/68/g' -e 's/stcol/'$5'/g' -e 's/encol/'$6'/g' -e 's/brdtype/'$1'/g' -e 's/brdtxt/'$3'/g' -e 's/demotxt/Total '$2'/g' -e 's/bantxt/ban_'$7'/g' -e 's/validcodes/'$4'/g' run > runx

# 3  
Old 03-22-2010
My suspicion is that nothing is wrong with your sed line (save for the fact that it could be written more easily as frans has pointed out) but the problem is here (marked red):

Code:
TEXT = "Power Tools or Accessories"

In practically all shells whitespace are special characters and there mustn't be any spaces in variable declarations:

Code:
x="abc"
x = "abc"

will yield different results with the first line probably giving the expected one.

I hope this helps.

bakunin
# 4  
Old 03-22-2010
still not working

I have tried by deleting blanks but it's thorwing error like unidentified reference...

and then I have changed it as TEXT ="Power Tools or Accessories"
then I am getting blank in the output

i am working on some another softwere and "run" is the file I actually need to run, but i have about 50 statements like the one I am passing and just to avoind the lenght of the scripting i want to pass this somwhow....

---------- Post updated at 02:06 AM ---------- Previous update was at 02:01 AM ----------

Quote:
Originally Posted by frans
Not very clear
what contains 'run' ?
what's 'run.do' ?
the sed line could be written whithout cat & pipe :
Code:
 sed -e 's/SRT/'$8'/g' -e 's/plength/68/g' -e 's/stcol/'$5'/g' -e 's/encol/'$6'/g' -e 's/brdtype/'$1'/g' -e 's/brdtxt/'$3'/g' -e 's/demotxt/Total '$2'/g' -e 's/bantxt/ban_'$7'/g' -e 's/validcodes/'$4'/g' run > runx



Thanks Frans, i am really not that familiar with shell and trying to make my work somewhat easier by googling for shell, and really thnx for letting e know this new way of scrpting..
# 5  
Old 03-22-2010
not TEXT ="Power Tools or Accessories"
but TEXT="Power Tools or Accessories"
# 6  
Old 03-22-2010
it's throwing error

have tried this one also but it's throwing error and output came as blank completely
# 7  
Old 03-22-2010
In this case post some complete data: the script, the input, the associated files, the desired output. Otherwise it is like trying to solve a puzzle you are not allowed to even know.

bakunin
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