Hello, On Sat, 01 Oct 2011, David C. Rankin wrote:
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??
Well, the test-binary / [ symlink, the shell builtin test / [ alias are quite portable (except -a/-o stuff). [[ ]] is relatively new AFAIK. Search for '\[\[' in man bash for [[ expression ]] to read up on what [[ ]] can. 'test' is much simpler (e.g. no pattern matching). For the stuff that 'test' can do (e.g. testing for existance), I prefer it and also to use 'test EXPR' instead of '[ EXPR ]', esp. because the latter needs the 'space]' sequence at the end (makes for ugly bugs if you use '[ EXPR];' by mistake, and also because it makes people think that [ ] is shell-syntax like [[ ]] or () or {}, which gets you stuff like (real world example): if [ "`ls /media/ | grep "device name"`" != "" ]; then [..]
## 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 :)
In this case you'd need to look into 'man date' or rather 'info date'.
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|
That looks as if the format of the lines is: "filename" frame/time stuff\n\rspaces\r Or rather (except on the first line): \rspaces\r"filename" frame/time stuff\n So, yes, you can combine that with the grep: getdates() { OLDIFS="$IFS" IFS=$'\n' clipct=1 ### 'for..do' broken into 3 lines for this mail only for dt in $(sed -n '/"dcrv/s/^\(\r +\r\)?"dcrv-\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)_.*'/\3\/\2\/\1/p' "$tmpfn" ); do test $clipct -eq 1 && first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS="$OLDIFS" } Oh, I see that you want to have $tmpfn also "as is" in the $tmpapp. Then you should just use the sed -i 's/^[[:space:]]*\r//' $tmpfn instead of cat $tmpfn | sed 's/^[[:space:]]*\r//' > /tmp/fix.log cp /tmp/fix.log $tmpfn and leave getdates as it were or use getdates() { OLDIFS="$IFS" IFS=$'\n' clipct=1 for dt in $(sed -n '/"dcrv/s/"dcrv-\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)_.*'/\3\/\2\/\1/p' "$tmpfn"); do test $clipct -eq 1 && first_dt="$dt" ((clipct++)) done last_dt="$dt" IFS="$OLDIFS" } Yes, the sed looks ugly and complicated but is actually quite simple ;) -dnh -- Q: "Excession is particularly popular because of its copious detail concerning the Ships and Minds of the Culture, its great AIs: their outrageous names, their dangerous senses of humour. Is this what gods would actually be like?" A: "If we're lucky." -- Iain M. Banks -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org