Argument Problems with ncftpput


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Argument Problems with ncftpput
# 8  
Old 08-08-2012
Quotes do not work that way. Instead of wondering why, just test what they actually do:

Code:
$ var="asdf"

$ echo '"$var"'

"$var"

$ echo "'$var'"

'asdf'

$ echo "$var"

asdf

$

Therefore, shell doesn't actually do what you think it does.

Putting variables in double-quotes is a good idea when you don't want them to split. Single quotes don't evaluate variables at all. And extra quotes inside double quotes don't get evaluated, just stick around.
# 9  
Old 08-10-2012
Quote:
Originally Posted by Corona688
Quotes do not work that way. Instead of wondering why, just test what they actually do:

Code:
$ var="asdf"

$ echo '"$var"'

"$var"

$ echo "'$var'"

'asdf'

$ echo "$var"

asdf

$

Therefore, shell doesn't actually do what you think it does.

Putting variables in double-quotes is a good idea when you don't want them to split. Single quotes don't evaluate variables at all. And extra quotes inside double quotes don't get evaluated, just stick around.
Okay, I understand now.

My code is now:
Code:
#/bin/bash

echo "Running command: ncftpput -R -u "$2" -p "$3" "$1" "$5" "$4""
ncftpput -R -u "$2" -p "$3" "$1" $5 $4

Code:
./ftpWebsite.sh '1.2.3.4' 'username.co.uk' 'pass.!pass' /var/www/vhosts/username.co.uk/httpdocs/ /public_html

This - WORKS! Smilie

Code:
./ftpWebsite.sh '1.2.3.4' 'username.co.uk' 'pass.!pass' /var/www/vhosts/username.co.uk/httpdocs/* /public_html

This however, doesn't, with the * to denote the contents of the folder, not the folder itself, it complains about not being able to change to a directory, and the "directory" it lists, is the first file in that folder... how do I use *?

Thanks in advance.

---------- Post updated 08-10-12 at 06:49 AM ---------- Previous update was 08-09-12 at 07:19 AM ----------

Sorry to bump, but I'm still having troubles with this script...could anybody point me in the right direction?
# 10  
Old 08-10-2012
The shell will expand that into a lot more than $4. You'd need to shift off 1-3, then use "$@"
# 11  
Old 08-10-2012
Sorry, I don't fully understand that. I know I'm coming across as wanting to be spoonfed Smilie

What do you mean by the shell will expand into more than $4? how do you 'shift off'? I understand $@ is all arguments separated with a space, but I am still unclear as to the rest.
# 12  
Old 08-10-2012
It means you could also end up with $5, $6, $7, ... depending on how many files * finds. You're not putting a literal * into ncftp, and if you did, it probably wouldn't work. It's the shell's job to turn * into filenames for you ahead of time.

You shift with the shift command. It works like this:

Code:
set -- a b c d e # Set $1=a, $2=b, $3=c, ... for example

echo $1 # Should print a

shift 2 # Get rid of the first two

echo $1 # should print c
echo $2 # should print d
echo $3 # should print e
echo "$@" # should print c d e

"$@", quotes and all, is a special operator which means "all arguments". So if you get rid of the first few arguments, you can feed "$@" into your FTP program and feed it all the arguments instead of hardcoding $1 $2 $3 $4 etc.

Last edited by Corona688; 08-10-2012 at 10:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

2. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

3. UNIX for Dummies Questions & Answers

Argument in Linux

I am trying to see the commands that can work also with only one argument. I tried that man to see the commands details but could not figure out. Here in my scenario I have ln, cp and mv commands. I am trying to see if these command can also work with just one argument. It looks like cp works if I... (3 Replies)
Discussion started by: linux17
3 Replies

4. Shell Programming and Scripting

argument

Im sorry but I'm in need of help. How would I give the user the option to include the name of an html file as an arugment for the script? but if none is provided, then the script should prompt the user for the file name. I have sed 's/<*>//g' yourfile.html | uniq >newfile.txt so far I have... (7 Replies)
Discussion started by: clicstic
7 Replies

5. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

6. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

7. Shell Programming and Scripting

Strict Argument

Im trying to write a bash script that has an if statment that when the user enters ONLY that exact argument, will echo what follows that conditon. For example: for file in $1 do if then Var1=$(cat hello | egrep "that pattern" | awk '{ print $NF }') cat $Var1 fi done Basically,... (3 Replies)
Discussion started by: oxoxo
3 Replies

8. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies

9. Shell Programming and Scripting

argument help

if i have 2 arguments $1 and $2 how can i append them so that $2 is added to $1? It is really confusing me because it seems so simple, yet i can't get the shell script to work properly. Thanks. (2 Replies)
Discussion started by: brentdeback
2 Replies

10. UNIX for Advanced & Expert Users

'make' problems (compliation problems?)

I'm trying to compile and install both most recent version of 'make' and the most recent version of 'openssh' on my Sparc20. I've run into the following problems... and I don't know what they mean. Can someone please help me resolve these issues? I'm using the 'make' version that was... (5 Replies)
Discussion started by: xyyz
5 Replies
Login or Register to Ask a Question