Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cap=$(exiv2 -g Iptc.Application2.Caption -Pv "$fg")
if [[ -f "$cap" ]]; then
echo -e "$fg \e[1mhas\e[0m a Caption."
clen=${#cap}
echo -e "The caption for $fg is $clen characters long (spaces included)."
echo -e "$fg:\\t$clen" >> captionlengths.txt
fi
work when C&P'd (cut and pasted), but not when run as a script (see attached).
(Aside: I'm too much of a cheesehead nowadays to learn printf without having a book like the ABS, sorry about that.)
As usual, please advise corrections (preferably using echo's, .)
Oh and my DM is now Kubuntu 20.04 and change (whatever the latest maint. upgrade is).
It would help enormously if you stated what you expect from the script and what happens when you run it as a script. The attached file doesn't show anything failing.
Also, I doubt the meaning of C&P is clear to everybody (not to me anyway), so you may want to clarify that.
It would help enormously if you stated what you expect from the script and what happens when you run it as a script. The attached file doesn't show anything failing.
Also, I doubt the meaning of C&P is clear to everybody (not to me anyway), so you may want to clarify that.
My issue is, when I run it, the script hangs and doesn't echo the length of each caption or write the text file (at all). I get that when I cut and paste line 20, but again, not when the script runs.
I hope that explains what I'm looking for help with.
Have you tried running the script with the -x option? E.g. bash -x nameofyourscript. It outputs the details of each command it executes.
If the script doesn't execute the echo's, I would assume that there is no file named $cap and investigate why. When you leave the echo $fg in, is the output as expected?
The attached file and the code you pasted are not identical; how would they give the same results?
I don't understand what you're getting at.
What if you reduce the script to the exact same code that works when "C&P"'d on the command line?
How can it even work on the command line when $fg isn't defined?
Please always show us actual output of actual commands ("C&P" the terminal output) instead of praphrasing.
cap is not a file (if I understand well) so [[ -f $cap ]] is just wrong.
but as it was already told: we cannot suggest you anything if we have no idea: what is it all about.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
Quote:
Originally Posted by pan64
cap is not a file (if I understand well) so [[ -f $cap ]] is just wrong.
but as it was already told: we cannot suggest you anything if we have no idea: what is it all about.
And what is the script supposed to do if "$cap" doesn't refer to a file? Or is a null string?
I'd suggest the OP's coding be more defensive and issue error messages when bad/incorrect data is encountered (which could very be the norm and not the exception) rather than simply forging ahead and feeding it into the rest of the script where weird errors can occur.
Something like:
Code:
if [ -z "$cap" ]; then
echo "FATAL: You must specify a file!"
RC=1
else
if [ ! -f "$cap" ]; then
echo "FATAL: \"$cap\" is NOT a file!"
RC=1
else
#
# Do something using the file...
#
...
RC=0 (unless other errors occur)
fi
fi
exit $RC
as a start. Too much code gets written as though nothing will ever fail. Burns you every time.
And what is the script supposed to do if "$cap" doesn't refer to a file? Or is a null string?
You've misread something.
What the script appears to be attempting is appending a list of image filenames and caption lengths to a file, but only when the caption contains a value.
What Pan is saying is that the command "[font=monospace]cap/font]" is populated from doesn't give a filename - it gives IPTC Caption metadata - and nothing in the rest of the script implies that caption contains anyhting other than just text, so the file test is most likely meaningless, and (based on the then output) should probably be -n instead.
Another problem with the script is using "white read fg" when it should probably be "while IFS= read -r fg" (or similar).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.