Bash: mv command and arguments
I'm writing a script so that instead of removing files with rm I have my own way or doing so and it puts files into a folder in the tmp directory heres where i run into issues. for now I can't mv any files there through my script using the second argument as the file to move so I have
Code:
mv: cannot stat '': No such file or directory so some reason mv isn't picking up argument 2 of my script. Any ideas? |
Put
set -xv After your hashbang line. Then run the script again, and it will give you some useful debugging output. |
it's giving me exactly what I told you is happening mv isn't grabbing $2 cause it shows it gets to recycle_files and then mv -v '' /tmp/recycle_bin mv: cannot stat '': No such file or directory
hope it helps to have confirmed it though :) |
@fatalerror0x00: What does "$2" mean in your script?
|
Code:
[root@beastlinux ~]# touch garbage When you use $2 in a function, that means the 2nd argument passed to that function which was nothing when you were trying to run it. So I take the 2nd argument from the command line and pass it to the function. In the function, that is the first argument passed. |
$2 is the second argument so when I type in rcbin -r test3
rcbin is $0 the command you type $1 is -r the first argument and test3 is $2 it's a simple way of doing arguments and for me it's effective I guess there are other and better ways but this is the only method I know and it works great for me :) alright code given works after I realized I type $2 at the end of the wrong function :P thank you guys :) |
Code:
#!/bin/bash |
All times are GMT -5. The time now is 06:21 AM. |