|
Home > Archive > Unix Shell > December 2006 > bloks of commands between && and ||.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
bloks of commands between && and ||.
|
|
| slystoner 2006-12-18, 7:21 pm |
| I'm not able to do something like that:
command && ("execute this list of commands") || ("other list of commands")
this is my code (into a case block)
.....
rar )
mkdir "${FILE%.*}"
mv "$FILE" "${FILE%.*}"
cd "${FILE%.*}"
(unrar x "$FILE" && rm "$FILE") || (echo $FILE >> $log_file; mv
"$FILE" $1 ; cd $1 ; rm -r "${FILE%.*}")
cd $1 ;;
....
| |
| Chris F.A. Johnson 2006-12-18, 7:21 pm |
| On 2006-12-18, slystoner wrote:
> I'm not able to do something like that:
> command && ("execute this list of commands") || ("other list of commands")
if command
then
: execute this list of commands
else
: other list of commands
fi
> this is my code (into a case block)
>
> ....
> rar )
>
> mkdir "${FILE%.*}"
> mv "$FILE" "${FILE%.*}"
> cd "${FILE%.*}"
> (unrar x "$FILE" && rm "$FILE") || (echo $FILE >> $log_file; mv
> "$FILE" $1 ; cd $1 ; rm -r "${FILE%.*}")
> cd $1 ;;
> ...
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| slystoner 2006-12-18, 7:21 pm |
| Chris F.A. Johnson ha scritto:
> On 2006-12-18, slystoner wrote:
>
> if command
> then
> : execute this list of commands
> else
> : other list of commands
> fi
>
tank you,
but, it's very strange: if i type 'unace' in a simple bash it works, if
I type:
ace )
mkdir "${FILE%.*}"
mv "$FILE" "${FILE%.*}"
cd "${FILE%.*}"
if unace x "$FILE" ; then
rm "$FILE"
else
echo $FILE >> $log_file
mv "$FILE" $1
cd $1
rm -r "${FILE%.*}"
fi
cd $1 ;;
it doesn't work. :|
probably it's a problem concerning unace.
| |
| Chris F.A. Johnson 2006-12-19, 1:30 am |
| On 2006-12-19, slystoner wrote:
> Chris F.A. Johnson ha scritto:
> tank you,
> but, it's very strange: if i type 'unace' in a simple bash it works, if
> I type:
>
> ace )
>
> mkdir "${FILE%.*}"
> mv "$FILE" "${FILE%.*}"
> cd "${FILE%.*}"
> if unace x "$FILE" ; then
> rm "$FILE"
> else
> echo $FILE >> $log_file
> mv "$FILE" $1
> cd $1
> rm -r "${FILE%.*}"
> fi
> cd $1 ;;
>
>
> it doesn't work. :|
What does "doesn't work" mean? What happens? What error messages
do you get?
Your script should also check that commands such as mkdir and cd
succeed.
> probably it's a problem concerning unace.
What is unace?
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| slystoner 2006-12-19, 7:32 am |
| Chris F.A. Johnson ha scritto:
>
> What does "doesn't work" mean? What happens? What error messages
> do you get?
nothing, the script stay in idle after the block into che 'ace' case:
mkdir "${FILE%.*}"
mv "$FILE" "${FILE%.*}"
cd "${FILE%.*}"
BUT the same block gives no prolems in 'rar' case!
>
> Your script should also check that commands such as mkdir and cd
> succeed.
>
This is the whole my script:
#!/bin/bash
# scompatta.sh: given a path, the script extract
# (with fill paths) all the zip,rar,ace files
# in a dir with the same name of the file
log_file=/home/slystone/Documenti/log_SCOMPATTATORE
cd $1
echo "$(ls *.zip *.rar *.ace 2>/dev/null)" | while read i;
do
# check the suffix
if [ $# != 1 ]; then
echo "scompatta.sh: Bad usage. Syntax \"scompatta.sh <path>\""
exit 1
else
FILE="$i"
fi
if [ "${FILE//./}" = "$FILE" ]; then
echo "scompatta.sh: Bad usage. The filename \"$FILE\" has no
extension."
exit 1
fi
# calculate extension
EXT=${FILE##*.}
case $EXT in
zip )
unzip "$FILE" -d "${FILE%.*}" && rm "$FILE" || echo $FILE >>
$log_file ;;
ace )
mkdir "${FILE%.*}"
mv "$FILE" "${FILE%.*}"
cd "${FILE%.*}"
if unace x "$FILE" ; then
rm "$FILE"
else
echo $FILE >> $log_file
mv "$FILE" $1
cd $1
rm -r "${FILE%.*}"
fi
cd $1 ;;
rar )
mkdir "${FILE%.*}"
mv "$FILE" "${FILE%.*}"
cd "${FILE%.*}"
unrar x "$FILE" && rm "$FILE" || echo $FILE >> $log_file
mv "$FILE" $1 ; cd $1 ; rm -r "${FILE%.*}")
cd $1 ;;
* )
echo "scompatta.sh: \"$FILE\" has not a valid suffix" 1>&2
exit 1
esac
done
exit 0
>
> What is unace?
>
slystone@lazy:~$ aptitude search unace
i unace
- uncompress .ace files
i unace-nonfree
- extract, test and view .ace archives (non-free version)
|
|
|
|
|