Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Space calling a script

Status
Not open for further replies.

tcardoso

Programmer
Joined
Jan 31, 2005
Messages
56
Location
PT
Hello, I want to call a script:

./my_script file1 file 2

My problem is that in the script $1 is file1 (OK), but $2 is file (WRONG), and i want it to be <file 2>

I tried:

./my_script file1 file\ 2 or ./my_script file1 "file\ 2"

But it doesn't work :|

Thanks in advance
Telmo Cardoso
 
Just quoting it should work (with no back slash before the space). This...
Code:
#!/bin/ksh

VAR1=$1
VAR2=$2

print "Var 1 = $VAR1"
print "Var 2 = $VAR2"
...gives me...
Code:
$ my_script file1 "file 2"
Var 1 = file1
Var 2 = file 2
$
What shell are you using? Can you post your code? It might be how you are using [tt]$2[/tt] that's causing the problem.
 
My script is

#!/bin/bash
echo $1
echo $2

/usr/bin/smbclient //machine/directory password
-c "put /home/$1/$2 /remote_directory/filename" (this two lines is only one line, this works correctly in bash mode).

The result to ./myscript file1 file 2 is:
file1
file 2
/home/file1/file does not exist

Telmo Cardoso
 
Ok, the problem isn't that it can't take in the variable with a space. Your [tt]echo $2[/tt] shows that. The problem is with the parameter of your [tt]smbclient[/tt] command.

Just a guess, try this...
Code:
#!/bin/bash
echo $1
echo $2

FILE="/home/$1/$2/remote_directory/filename"

/usr/bin/smbclient //machine/directory password -c "put \"${FILE}\" "
That will try to pass the quotes around the filename with the command. The filename needs to be quoted if there are spaces anywhere in the path or filename.

Another way to fix it is to not have any spaces in directory or file names.

Also, please enclose your code in [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] tags. It makes it much easier to read.
 
Thanks ;)

it worked! Sorry for the code mixed with the text, next time wont happen.

Telmo Cardoso
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top