You are not logged in.
Hi I want to creat a nautilus script to compress the file to rar package.
This is my script
#!/bin/bash
#不对空格进行分隔处理
IFS=$'\t\n'
filePath=""
index=0
for path in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
fileName=`basename $path`
fileName=`echo "'$fileName'"`
if [[ $index == 0 ]];then
filePath="$filePath$fileName"
else
filePath="$filePath $fileName"
fi
((index++))
done
rarpackage=新建rar压缩包.rar
cmd="result=\$(rar a $rarpackage $filePath 2>&1) \nif [[ \$result == *\"Done\"* ]];then\n notify-send -a rar压缩 -u normal \"成功\" \"创建$rarpackage成功\"\nelse\n notify-send -a rar压缩 -u normal \"失败\" \"请检查文件名是否正常\"\nfi"
echo -e $cmd > temp.sh
chmod +x temp.sh
`bash temp.sh`
rm temp.sh
The file name I have use the single quote, just for some special character problem,but when I run the script,it tell me the file can not found.
for example
result=`rar a 1.rar '1.txt' `
So I have create the temp.sh,and the script is ok,but I think this is not a good idea.
Anyone can tell me how to fix this problem?
thanks
Last edited by jiangkero (2024-05-12 04:53:24)
Offline
Maybe use list of parameters to your command: "$@" or "$*" :
https://stackoverflow.com/questions/516 … -variables
Offline
Why are you stripping the paths from the filenames?
What does $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS actually look like?
Why can't you just
rar a $rarpackage $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
?
For general remarks, don't use the backtick syntax and you could just "eval" the command IFFF that was really necessary
Offline
thanks
Offline
In case it is, please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Offline