[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gcmd-usr] Passing multiple file pathes to shell scripts
From: |
mi |
Subject: |
[gcmd-usr] Passing multiple file pathes to shell scripts |
Date: |
Sat, 9 Jul 2022 04:22:41 +0200 |
I created a simple script which moves a file into my $HOME.
____________________
#!/bin/sh
xmessage "$1"
mv -v $1 $HOME
exit
____________________
and configured a gcmd program which invokes it with %u (also checking
'multiple files'). I tested passing of %u with output of $@ - that part works
fine.
But it dii'nt work because
[LL] sync_dir_list: /home/micha/.config/gnome-commander/scripts
[GG] running: /opt/TOOLS/test.sh %u
Warning: Missing charsets in String to FontSet conversion
mv: cannot stat 'file:///tmp/testfile': No such file or directory
apparently, gcmd passes the file path as URI with preceeding 'file:///' and a
plain shell won't understand this without 'sed' mangling.
In the past (gcmd 1.2), file pathes were emitted anyway, without any % argument
configured, and they were simple shell pathes. But it seems the newer version
requires configuring a % parameter in gcmd programs, without that gcmd outputs
nothing at all. So now we have to deal with URI parsing.
The typical sed line could look lilke sed 's / file: \/ \/ / /g' (without the
whitespaces i put for readability); and you could throw this on $@ like
files=$(echo $@ | sed 's/file:\/\///g') and if you want to read the files
later off a list line-by-line (which is safer in case of whitespaced filenames)
then you could replace the URI thing just with \n.
But there is an issue with the first line being empty and then, gcmd also
replaces whitespaces with %20 which you need to convert with sed or printf; so
it's still a little more complicated.
To make it short, here is an example how the file parsing can be done:
basedir=`pwd`
targetdir=$basedir/TEST
mkdir $targetdir
files=$(echo $@ | sed 's/file:\/\//\\n/g' | sed 's/%20/ /g')
# xmessage "$files"
echo -e $files | grep -vx "" | while read file; do
mv "$file" $targetdir;
done
- [gcmd-usr] Passing multiple file pathes to shell scripts,
mi <=
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, mi, 2022/07/08
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, Uwe Scholz, 2022/07/11
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, mi, 2022/07/12
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, mi, 2022/07/12
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, mi, 2022/07/12
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, mi, 2022/07/12
- Re: [gcmd-usr] Passing multiple file pathes to shell scripts, Uwe Scholz, 2022/07/14