Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i write bash file to copy files from unix to windows and i pass the path of files as parameter to bash file :- scp -r /$1/ user@hostname:/cygdrive/c/unix_file

when i execute the bash and don't pass any parameter it is copy all file in "current directory "

example :-

roor@hostname/>./bash.sh now it copy all file in root .... when i test exit code it is equal ( 0 ) !!!!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

If you don't pass an argument then its parameter value is considered to be an empty string. Test the parameter for a zero-length string (with if and [ or [[) and fail if it is one. And don't forget to quote the parameter in the command (scp ... /"$1"/ ...).

share|improve this answer
add comment

If you want to specify a default directory that will be in effect if you don't supply a parameter:

scp -r "/${1:-default/directory}/" user@hostname:/cygdrive/c/unix_file

in which you would replace "default/directory" with whatever you'd like.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.