You are not logged in.

#1 2024-05-12 04:52:13

jiangkero
Member
Registered: 2009-07-25
Posts: 30

need some help for my nautilus script

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

#2 2024-05-12 09:57:03

xerxes_
Member
Registered: 2018-04-29
Posts: 766

Re: need some help for my nautilus script

Maybe use list of parameters to your command: "$@" or "$*" :
https://stackoverflow.com/questions/516 … -variables

Offline

#3 2024-05-12 13:37:24

seth
Member
Registered: 2012-09-03
Posts: 58,238

Re: need some help for my nautilus script

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

#4 2024-05-20 02:27:48

jiangkero
Member
Registered: 2009-07-25
Posts: 30

Re: need some help for my nautilus script

thanks

Offline

#5 2024-05-20 07:22:06

seth
Member
Registered: 2012-09-03
Posts: 58,238

Re: need some help for my nautilus script

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

Board footer

Powered by FluxBB