BASH: getting a script to "do" what's after "done"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers BASH: getting a script to "do" what's after "done"
# 8  
Old 08-25-2010
Here's "why" in spades.

Quote:
Originally Posted by Corona688
Why are you backing up and restoring IFS? I don't see that you're using any commands that care what that special variable's value is.
Spaces in file names as they're being evaluated. I just ran the finished script, sans IFS switching, and got some of this as stderr:
Code:
Evaluating  #92 of 164, happy older redhead.jpg...
happy: Failed to open the file
Exiv2 exception in print action for file happy:
happy: Failed to open the data source: No such file or directory (errno = 2)
older: Failed to open the file
Exiv2 exception in print action for file older:
older: Failed to open the data source: No such file or directory (errno = 2)
redhead.jpg: Failed to open the file
Exiv2 exception in print action for file redhead.jpg:
redhead.jpg: Failed to open the data source: No such file or directory (errno = 2)
happy older redhead.jpg: No PhotoFiltre software tag found.

BASH was "happy" (pvmi) to re-assemble the file name for me, but Exiv2 can't deal with spaces in filenames without an IFS customisation (when not reading from a 'command file,' and in the case of those it balks on unescaped extra punct. like whacks and backwhacks).

Just some FYI really. Wanted to be sure we were all on the same sidewalk with this.

BZT

---------- Post updated at 14:51 ---------- Previous update was at 14:24 ----------

Quote:
Originally Posted by agama
On the matter of redirecting errors, could you redirect the stderr from each invocation of the 'photo software' rather than the whole script. That'd give you a bit more slience, yet still see 'operational' errors from the script. Just a thought -- glad to have helped.
Well, except for the ones it shares with the shell (file not found etc), Exiv2's errors are, as I explained, pretty "blind pew" and uninformative. What one would certainly want to know is what file threw up error X, Y or Z, and so far, I haven't been able to get a ($file,2)>/errors.txt or even a pairing of the file name and its error/s redirected to the /dev/null bitbucket. I'll keep trying, of course, but I think I may have, in the end, to wait for Andreas Huggel to mod the error reporting in his app.

In the meantime, a "dummy patch" to match the "dumbo error reporting" in Exiv2 might just be the thing to keep the screen less noisy and distinguish command errors from shell ones. In bash, it often happens that stderr redirects in scripts get ignored (personal experience as well as reading a lot of forum and BB ink on the Web are my sources on that). I don't know what they're doing over at GNU, but it's obvious they're not making it much easier for those of us who 'like' bash to keep on 'liking' it for the same reasons. This (no guarantees a 2>/dev/null will really bitbucket your error when run in a subshell) is one of those things.

BZT[COLOR="#738fbf"]

---------- Post updated at 15:52 ---------- Previous update was at 15:47 ----------

I google'd around looking for different methods of command/result error redirection from inside the script. This one seemed to suit and works well up to this point (knock on pressboard Smilie )

Lines 10-14 of my finished script now read:
Code:
MANY=$((exiv2 -g Exif.Image.Software -Pv $file) 2>/tmp/Error)
	ERROR=$(</tmp/Error)
	if [ ${#ERROR} -gt 0 ]; then
		echo -ne "$file:\n$ERROR\n">>fileerrors.txt
	fi
	rm /tmp/Error

Here I get the filename and all the errors. When the script exits, I can review the list and see what types of errors Exiv2 was running into with which files in folder X.

A nice "patch" of sorts; though only cleverly tweaked code, the silence is almost deafening in stdout, so I'm "promoting" it to a "patch" as of now Smilie

BZT

Last edited by SilversleevesX; 08-25-2010 at 04:55 PM.. Reason: 11 for 10; phrasing
# 9  
Old 08-25-2010
Quote:
Originally Posted by SilversleevesX
Spaces in file names as they're being evaluated.
Oh.

You can put filenames in quotes to avoid that. Stopping splitting by wedging IFS with a spork seems inelegant -- what if you need it?

"${FILENAME}"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

5. Solaris

The slices "usr", "opt", "tmp" disappeared!!! Help please.

The system don't boot. on the screen appears following: press enter to maintenance (or type CTRL-D to continue)...I checked with format command. ... the slices "0-root","1-swap","2-backup" exist. ...the slises "3-var","6-usr" -unassigned. :( (16 Replies)
Discussion started by: wolfgang
16 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question