Pass a string with spaces to a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass a string with spaces to a shell script
# 1  
Old 11-24-2009
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:
Code:
#!/bin/sh -vx
#######################################################
# generate_documentation (c) Ch.Affolter Nov. 2009 Version 1.0 #
#######################################################
echo "Project name is:   [$1]"

i wanna call the script like:

test_shell "my script name"

that generates the output: Project name is: my script name

Should be possible or not?

Thanks
vivelafete
# 2  
Old 11-24-2009
Of Course.

code
Code:
#!/bin/ksh
# myshell.sh
echo "$1"

output
Code:
chmod +x ./myshell.sh
> ./myshell.sh "This string has spaces"
This string has spaces

chmod +x makes the script file executable.
# 3  
Old 11-24-2009
Here is a hint

You'll need a loop with:
$* = all arguments.
$# = number of arguments.
# 4  
Old 11-24-2009
Thanks for the fast answer!
Truly i have to say that i hadn't the problem until i use sed which doesn't like the spaces.
I searched at the wrong place, but you helped me!
best regards!
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 write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

2. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. 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

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. 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

6. 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

7. 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

8. Shell Programming and Scripting

Not able to pass string with spaces in shell

I have to pass a sentence in a file, the specs are as: 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' >... (15 Replies)
Discussion started by: patilrakesh1984
15 Replies

9. 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

10. 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
Login or Register to Ask a Question