Re: [Cocoadialog-users] Bourne Shell Script Equivalent to Perl Script Sample for CocoaDialog Dropdo
Status: Beta
Brought to you by:
sporkstorms
From: Bill L. <wl...@sw...> - 2008-12-03 18:09:02
|
Thomas Patko <tp...@gm...> said: > Thanks Bill. That worked a treat. The final code that I used to accomplish > this portion of the coding is shown below (in case it is useful to anyone > else). In the recursion, I execute a command using the transient variable > $INPUT each time. Builds and runs fine together with Platypus. > > Cheers, > > Thomas > > CD="CocoaDialog.app/Contents/MacOS/CocoaDialog" > rv=`$1/Contents/Resources/$CD fileselect \ > --title "Select your Fireflly Input Files for Batch Job Submission" \ > --text "Select your Fireflly Input Files for Batch Job Submission" > --select-multiple --no-newline` > > if [ -n "$rv" ]; then > # determine number of items returned > NO_ITEMS=`echo -n "$rv" | wc -l` > NO_ITEMS=`expr $NO_ITEMS + 1` > echo "The number of files selected is $NO_ITEMS" > COUNT=0 > echo -n "$rv" | while [[ $COUNT -lt $NO_ITEMS ]]; do > read FILE > INPUT="$FILE" > echo "Running input file $INPUT" > COUNT=`expr $COUNT + 1` > done > else > echo "No Input file selected. Application aborted." > sleep 6 > exit 1 > fi I think that you have a problem and aren't aware of it! You are using: NO_ITEMS=`echo -n "$rv" | wc -l` Even if "$rv" is a multiline string (it contains one or more new-line characters), when you use "echo" without the "-e" option everything will come out on a single line! Now, since you have included the "-n" option, this even supresses the final new-line character. Playing around a little, 'echo -n "ANYTHING" | wc -l' always returns "0". "wc -l" seems to count the number of new-line characters since without the "-e" option to display the additional new-line characters, they are ignored and you have even supressed the final new line character. Running (the "\n" character is the new-line character): echo "line1\nline2\nline3" | wc -l returns "1", just a single line. Running: echo -e "line1\nline2\nline3" | wc -l returns "3", the three lines that you would expect. But running: echo -n "line1\nline2\nline3" | wc -l returns a big fat "0"! I don't think that this is what you want. I really think that you want to use: NO_ITEMS=`echo -e "$rv" | wc -l` If you use this instead you can ignore the next line with "expr" since the line count includes the final line yielding the expected number. I am guessing that you never selected more than one file in the "fileselect" dialog. By the way, everyone is always learning. I have never used the '-e' option to echo until Mark used it in his example, which caused me to look it up. I have been writing shell scripts for a long time! Thanks Mark for teaching me something new and useful. But what I heard is the '-e' option doesn't appear to always be portable among various shell interpreters. It may work on one system and not on another, so buyer beware and user be careful! Bill Larson |