用bashshelllinux制作USB复制程序
这是我用bashshell将所有fd数据复制到用bashshelllinux制作USB复制程序,bash,shell,Bash,Shell,这是我用bashshell将所有fd数据复制到home/user目录的代码 #!/bin/sh user=$(whoami) now=$(date +"%d.%m.%Y_%H.%M.%S") dir=$(mkdir $now) --> and here I want to create a folder as a place to copy the results according to datetime if [ -d /media/$user/foo ] the
home/user
目录的代码
#!/bin/sh
user=$(whoami)
now=$(date +"%d.%m.%Y_%H.%M.%S")
dir=$(mkdir $now) --> and here I want to create a folder as a place to copy the results according to datetime
if [ -d /media/$user/foo ]
then
echo "any media"
cp -r /media/$user /home/$user/$dir
else
echo "none of media attached"
fi
但是我运行的是代码,cp-r/media/$user/home/$user/$dir
也没有运行,它不会被复制到基于datetime的新创建的目录中,有什么建议吗?或
我的代码有问题吗?我建议替换
dir=$(mkdir $now)
与
如果目录创建出现问题,这将终止您的脚本。Btw.:
sh
()通常不是bash
()。或者使用mkdir-p
。我会尝试的,先生,如果可能的话,我会问是否有办法在后台运行sh程序,这样当检测到usb时,它会自动运行sh程序。我把它放在bashrc文件中,但它只在终端打开时运行。这可能会有所帮助:或者我读过,但我什么都不懂,但谢谢你的建议
mkdir "$now" || exit 1
dir="$now"