Re: Problem copying a folder/subfolders to another drive
fredx181 wrote: Fri Jan 03, 2025 4:34 pmd-pupp wrote: Fri Jan 03, 2025 4:14 pm@Governor I agree it is fun leaning and writing simple scripts. I started with setup scripts. After a new frugal install I would just run a script or two and most of my personalization was done.
BTW there is a second method for testing if a command worked or not. The exit code. Most command have an exit code of 0 if they worked ok. Check the man page to verify. It is stored in the variable $? and is overwrote by the next command that runs. You can check it with echo $?
But in case of find (edit: this case with the pipes) it seems to return always value 0
Check this and it still echoes "Script completed" (but also gives "find: '/BLAHBLA': No such file or directory", as it cannot find the directory)Code: Select all
DIR=/BLAHBLA find "$DIR" | sort | uniq -i --all-repeated=separate && echo "Script completed"
Code: Select all
find: '/BLAHBLA': No such file or directory Script completed
EDIT: but without the pipes to sort uniq etc... it gives error code 1
Code: Select all
DIR=/BLAHBLA find "$DIR" && echo "Script completed" find: ‘/BLAHBLA’: No such file or directory echo $? 1
EDIT2: So need to use PIPESTATUS :
Code: Select all
DIR=/BLAHBLA find "$DIR" | sort | uniq -i --all-repeated=separate [ $PIPESTATUS -eq 0 ] && echo "Script completed" || echo "There was an error"
output:
Code: Select all
find: '/BLAHBLA': No such file or directory There was an error
But that may only give exit status 1 if the path provided to find doesn't exist (as in this case), not sure though.
I imagine it is the same in Puppy as in msdos; the more pipes in a script, the slower the script is executed, because the OS has to create a temporary file for each pipe.
In an ideal world, exit codes might be checked for each command before assuming it is ok to send the output through a pipe. I had to do that a few of times in msdos, although it. was normally sufficient to rely on the last exit code... Is it one exit code at a time in Puppy, or can there be more than one simultaneously?