$script location1 location2
我是linux的新手,我试图制作一个bash脚本来移动数据,该脚本将像上面一样使用,我只是想知道如何将这些位置放入脚本中以进行修改。
Not sure what you are asking, but if you want to access command line arguments in a bash script you can do so by using the variables $1 - $n. They are numbered in the order you passed them to the script.
See here for some examples
If you call the script using the command line
$ script location1 location2
you can access the value of the two arguments using $1
and $2
. That is, if you script looks like
from=$1
to=$2
echo "Move files from $from to $to"
the output resulting from the above command line would be
Move files from location1 to location2
Note that you don't need to set from
and to
; you can use $1
and $2
anywhere you would another variable.
you can use variables $1, $2, ... for example, $script location1 location2 then in your script, you can get location1 as $1.
Here is a cool guide: http://mywiki.wooledge.org/BashGuide/Parameters#Special_Parameters_and_Variables
Within your bash script you can simply use the "mv" command to move your data, like so:
mv path/location1 path/location2
That's it!
If, in your script you first go to the directory containing the location1 data, you won't need to provide the path on the first one, like so:
cd path/
mv location1 path/location2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.