On 09/30/2011 07:58 AM, David Haller wrote:
## dir test
[[ -d /dat_e/dv/new ]] || { echo "No /dat_e/dv/new, exiting..."; exit 2; } I prefer to use the simple
test -d /dat_e/dv/new || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
<snip> I have see this the 'test <condition>' verses [[ <condition> ]] verses [ <condition> ] arguments a number of times and don't understand enough about the differences. I know the [[ <condition> ]] was an 'improvement' over the [ <condition> ] notation, but other than the flexibility test offers in testing for 'command' return success or failure rather than conditional <conditions> (eg. ==, -eq, etc...) I don't know where the primary concern lies. Posix compatibility?? Some 'tricks' still require the old [ <condition> ] or 'test' constructs and will not work with [[ <condition> ]]. For example the integer test: if [ $var -eq $var ] >/dev/null; then printf "\$var -- is an integer" else printf "\$var -- is NOT an integer" fi if test $var -eq $var >/dev/null; then printf "\$var -- is an integer" else printf "\$var -- is NOT an integer" fi Dunno why, but I know it is so :)
## read tape count and set up vars& tmp files tapect=${1:-$(</dat_e/dv/tapect.txt)} tmpfn=/tmp/dvtmp.log tmpapp=/tmp/dvapp.log :>$tmpfn :>$tmpapp first_dt="" last_dt=""
## fix date format from yyyy.mm.dd to mm/dd/yyyy fixdfmt() { [[ -n $1 ]] || { echo "ERROR: Nothing passed to function 'fixdfmt'"; return 1; } year=${1//.*} day=${1##*.} mo=${1%.*} mo=${mo##*.} echo "${mo}/${day}/${year}" return 0 } An fun alternative I came up with:
fixdfmt() { test -z "$1"&& { echo "ERROR: Nothing passed to function 'fixdfmt'">&2; return 1; } _fixdfmt() { echo "$3/$2/$1"; } oIFS="$IFS"; IFS="." _fixdfmt $1 IFS="$oIFS" # unset _fixedfmt }
Clearly shows the relative experience levels among authors - poetry verses a simple paragraph. Using IFS for it's intended purpose is clearly illustrated instead of using it as a hammer :)
## parse dates from $tmpfn to get start and end dates for tape index getdates() { OLDIFS=$IFS IFS=$'\n' clipct=1 for i in $(grep \"d $tmpfn); do dt=${i//\"dcrv-} dt=${dt//_*} [[ $clipct -eq 1 ]]&& first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS=$OLDIFS }
## download video with output to tmpfn& rewind tape when done echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn date '+\nCapture Started: %b %e %T\n' | tee -a $tmpfn
Damn, I knew I would have to look something up in 'man bash' in the course of this discussion :)
dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind
## fix the \r issue cat $tmpfn | sed 's/^[[:space:]]*\r//'> /tmp/fix.log cp /tmp/fix.log $tmpfn You could combine that with the grep. Do you get those \r on the same lines as the '"dcrv-'?
Alternatively:
sed -i 's/^[[:space:]]*\r//' $tmpfn
Err... umm..., I think so?? 00000060 2e 2e 2e 0a 43 61 70 74 75 72 65 20 53 74 61 72 |....Capture Star| 00000070 74 65 64 0a 22 64 63 72 76 2d 32 30 30 33 2e 30 |ted."dcrv-2003.0| 00000080 37 2e 32 37 5f 31 38 2d 30 35 2d 35 34 2e 64 76 |7.27_18-05-54.dv| 00000090 22 3a 20 20 20 39 39 39 2e 39 38 20 4d 69 42 20 |": 999.98 MiB | 000000a0 20 38 37 33 38 20 66 72 61 6d 65 73 20 74 69 6d | 8738 frames tim| 000000b0 65 63 6f 64 65 20 30 30 3a 30 34 3a 35 31 2e 31 |ecode 00:04:51.1| 000000c0 38 20 64 61 74 65 20 32 30 30 33 2e 30 37 2e 32 |8 date 2003.07.2| 000000d0 37 20 31 38 3a 32 36 3a 34 36 0a 0d 20 20 20 20 |7 18:26:46.. | 000000e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000120 20 20 20 20 20 20 20 20 20 20 20 20 0d 22 64 63 | ."dc| 00000130 72 76 2d 32 30 30 33 2e 30 37 2e 32 37 5f 31 38 |rv-2003.07.27_18| 00000140 2d 32 36 2d 34 36 2e 64 76 22 3a 20 20 20 32 39 |-26-46.dv": 29| 00000150 34 2e 30 30 20 4d 69 42 20 20 32 35 36 39 20 66 |4.00 MiB 2569 f| 00000160 72 61 6d 65 73 20 74 69 6d 65 63 6f 64 65 20 30 |rames timecode 0| 00000170 30 3a 30 36 3a 31 37 2e 31 31 20 64 61 74 65 20 |0:06:17.11 date | 00000180 32 30 30 33 2e 30 37 2e 32 37 20 31 38 3a 32 38 |2003.07.27 18:28| 00000190 3a 31 32 0a 0d 20 20 20 20 20 20 20 20 20 20 20 |:12.. | 000001a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * Actually, It looks like it is in a line by itself: 00000240 2e 31 34 20 31 38 3a 35 33 3a 35 39 0a 0d 20 20 |.14 18:53:59.. | 00000250 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0d 22 | ."| 000002a0 64 63 72 76 2d 32 30 30 33 2e 30 38 2e 31 36 5f |dcrv-2003.08.16_|
HTH, -dnh
It does, thanks! -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org