Help with bash script

on my laptop running KDE I would like to have a list with the exif metatag orientation for each picture,
if I make an executable file with this inside:

#!/bin/bash
exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg"
exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"
exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg"

and execute, the result is this:

pla@pla4-TW:~/bin/foto-comments> ./foto-0orient2.txt 
Orientation                     : Rotate 180
Orientation                     : Rotate 180
pla@pla4-TW:~/bin/foto-comments> 

the picture file.noorientation1.jpg hasn’t orientation exif metatag and it is not on the list,
what I would like as result is this:

pla@pla4-TW:~/bin/foto-comments> ./foto-0orient2.txt 
Orientation                     : Rotate 180
something here
Orientation                     : Rotate 180
pla@pla4-TW:~/bin/foto-comments> 

in order to have a list with the same number of elements as the pictures in the script
how can I get this?

When a picture never had an orientation tag, the output of exiftool will always be blank.

Hi hui, yes, for this I’m asking help, may be an if statement could help me, for example a script
with:
if orientation is blank
then echo blank
else orientation tag
fi
but I’m not able to translate this in bash script

I tried this:

#!/bin/bash
[ -z 'exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg"' ] && echo "NULL" || exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg"
[ -z 'exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"' ] && echo "NULL" || exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"
[ -z 'exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg"' ] && echo "NULL" || exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg"

but result is this:

pla@pla4-TW:~/bin/foto-comments> ./foto-0orient3.txt 
Orientation                     : Rotate 180
Orientation                     : Rotate 180
pla@pla4-TW:~/bin/foto-comments> 

it seems that orientation output is not blank, or not?
where am I wrong??

You could at least do a
ls -l <that file>
so we can see the name (makes it easy to talk about it and to see when you execute it) and also that it is indeed what you say.

And you could at least show what the output is from

exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"

And also from one of the other files.
so we can see what the difference is and what the script should act on.

Only so we can see if it is e.g. a blank line, or nothing at all, or …

Hi hcvv, this are the outputs:

pla@pla4-TW:~/bin/foto-comments> exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"
pla@pla4-TW:~/bin/foto-comments> ls -l "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg"
-rwxrwxrwx 1 root users 2255593 Feb 26 10:54 /dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg
pla@pla4-TW:~/bin/foto-comments> ls -l "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"
-rwxrwxrwx 1 root users 2252534 Feb 26 10:55 /dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg
pla@pla4-TW:~/bin/foto-comments> ls -l "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg"
-rwxrwxrwx 1 root users 2255593 Feb 26 10:55 /dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg
pla@pla4-TW:~/bin/foto-comments> 

the file “file.noorientation1.jpg” has no orientation EXIF tag
the files “file.orientation1.jpg” and “file.orientation2.jpg” have orientation EXIF tag

the outputs for exiftool orientation command are:

pla@pla4-TW:~/bin/foto-comments> exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg"
Orientation                     : Rotate 180
pla@pla4-TW:~/bin/foto-comments> exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg"
pla@pla4-TW:~/bin/foto-comments> exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg"
Orientation                     : Rotate 180
pla@pla4-TW:~/bin/foto-comments> 

the files “file.orientation1.jpg” and “file.orientation2.jpg” have output=Orientation : Rotate 180 output
the file “file.noorientation1.jpg” has nothing as output

I am very unsure about what the first code sections shows, so I will skip to interpret it.
Well, it seems that you have files there owned by “root” and group “users”. A very strange combination.

But the second section shows that there is indeed no output at all.
For a script, you could first catch the output:

RESULT="$(exiftool -orientation <file.jpeg>)"

and then test on emptiness

if [[ -z ${RESULT}  ]]
then    echo "no orientation specified"
else   echo "${RESULT}"
fi

And you still did not answer my first questions: what is the file name of your script!

orientation=$(exiftool -orientation ...)
if [ x"$orientation" = x ]; then
  echo "something here"
else
  echo "$orientation"
fi

This question is more in place on Programming/Scripting.

manythanks hcvv :smiley:
first the name of my script is
"foto-0orient(something depends on the test) .txt "
and to launch it I use
~/bin/foto-comments> ./foto-0orient(something depends on the test) .txt "

your script, modified with file name, gives me some errors:
this is the script

#!/bin/bash
RESULT="$(exiftool -orientation exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg")"
if [[ -z ${RESULT}  ]]
then    echo "no orientation specified"
else   echo "${RESULT}"
fi

RESULT="$(exiftool -orientation exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg")"
if [[ -z ${RESULT}  ]]
then    echo "no orientation specified"
else   echo "${RESULT}"
fi

RESULT="$(exiftool -orientation exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg")"
if [[ -z ${RESULT}  ]]
then    echo "no orientation specified"
else   echo "${RESULT}"
fi
fi

RESULT='$(exiftool -orientation exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg")'
if [[ -z ${RESULT}  ]]
then    echo "no orientation specified"
else   echo "${RESULT}"
fi

this is the output

pla@pla4-TW:~/bin/foto-comments> ./foto-0orientif2.txt 
Error: File not found - exiftool
======== /dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg
Orientation                     : Rotate 180
Orientation                     : Rotate 180
    1 image files read
    1 files could not be read
Error: File not found - exiftool
======== /dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg
    1 image files read
    1 files could not be read
Error: File not found - exiftool
======== /dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg
Orientation                     : Rotate 180
Orientation                     : Rotate 180
    1 image files read
    1 files could not be read
pla@pla4-TW:~/bin/foto-comments> 

but you led me towards something that seems to works :smiley:
this is the script

#!/bin/bash
var=$(exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation1.jpg") && echo "azz"$var
var=$(exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.noorientation1.jpg") && echo "azz"$var
var=$(exiftool -orientation "/dati/a-FOTO-x-amici/2013/2013-12-31dic(foto scrive sopra)/file.orientation2.jpg") && echo "azz"$var

this is the output

pla@pla4-TW:~/bin/foto-comments> ./foto-0orient4.txt 
azzOrientation : Rotate 180
azz
azzOrientation : Rotate 180
pla@pla4-TW:~/bin/foto-comments> 

manythanks

Because you call the same command twice… :face_with_raised_eyebrow:

As hui already found out. This is complete nonsense.

Are you even trying to understand the hints I gave. I do not hint you so that you malform and mis-use it. It do so that you at least try to understand the commands and the constructs. By reading e.g. your bash course material and the man page. And when you fully understand what things mean, then you will be able to use them for your case.

aaahhh, you are right :smiley:
now it works :star_struck:

pla@pla4-TW:~/bin/foto-comments> ./foto-0orientif2.txt 
Orientation                     : Rotate 180
no orientation specified
Orientation                     : Rotate 180
pla@pla4-TW:~/bin/foto-comments> 

I try for the third (and final) time. Should we understand that the name of your script is foto-0orientif2.txt ?

Moved to Programming/Scripting