pot*_*day 0 command-line bash scripts
我们应该如何将正在执行的脚本从一个文件夹复制到另一个文件夹?
脚本内容为:
#!/bin/sh
zenity --forms --title="Add Friend" \
--text="Enter information about your friend." \
--separator="," \
--add-entry="First Name" \
--add-entry="Family Name" \
--add-entry="Email" \
--add-calendar="Birthday" >> addr.csv
case $? in
0)
echo "Friend added.";;
1)
echo "No friend added."
;;
-1)
echo "An unexpected error has occurred."
;;
esac
Run Code Online (Sandbox Code Playgroud)
假设我已将上述脚本保存为test.shin home/user/Documents/sh/,当我通过双击执行test.sh 时,它应该将自身复制到meow文件夹中home/user/wow/meow/。
我不确定您为什么要这样做,但是您可以比原始副本更优雅地处理它。
mkdir -p $HOME/wow/meow
cp "$(readlink -f $0)" "$HOME/wow/meow"
Run Code Online (Sandbox Code Playgroud)
$HOME所以我们不依赖于硬编码路径(比~脚本的替代更可靠)。