0

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 ) !!!!

Mohammad AL-Rawabdeh
  • 1,612
  • 12
  • 33
  • 54

2 Answers2

1

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"/ ...).

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
1

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.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151