LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-13-2018, 11:12 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Error on the #!/bin/bash line?


Code:
#!/bin/bash

set -xv

function mongol() {
echo -e "What list will I be using?"
read -er smash
}
mongol
echo "$smash"
while IFS=":" read -er fg rg
do
echo "$fg"
pg=$(perl -e "print $fg*12.75")
echo "$rg"


exiv2 --keep -M"set Xmp.xmp.Rating $rg" -M"set Xmp.xmp.RatingPercent $pg" "$fg"  2>/dev/null
echo "$fg now has a MS Photo Rating of $rg."
done< "$smash"
files=(*temp)
	echo "$files">>killtemp.log
    rm "$files" 2>/dev/null
   	echo "Done."
That's what I get when I run it.

Shellcheck errors include (installed, online checks out fine):
Code:
line 22:
        echo "$files">>killtemp.log
              ^-- SC2128: Expanding an array without an index only gives the first element.
I'm at a loss.
(And you will note that the script, as pasted here, starts with a "set -xv.)

Carver
 
Old 11-13-2018, 11:17 AM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
That's what I get when I run it.
What's what you get when you run it?

Do you not understand the warning?
 
Old 11-13-2018, 11:21 AM   #3
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by L_Carver View Post
Shellcheck errors include (installed, online checks out fine):
Code:
line 22:
        echo "$files">>killtemp.log
              ^-- SC2128: Expanding an array without an index only gives the first element.
I'm at a loss.
For me it's just a warning for you to be reviewed if need be...
 
Old 11-13-2018, 02:47 PM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,145
Blog Entries: 6

Rep: Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832
Quote:
For me it's just a warning for you to be reviewed if need be...
It's a warning for you to correct.

Code:
array=(
one
two
three
four
)

echo "$array"
one

echo "${array[@]}"
one two three four
 
Old 11-14-2018, 06:55 AM   #5
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by teckk View Post
It's a warning for you to correct.
Technically speaking, echo "$array", is totally ok.
If it is to be corrected eventually, that's just because it's not what the OP expected initally when he coded it (and I agree with you it's probably not the case indeed -> echo "${array[@]}").
 
Old 11-14-2018, 07:50 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
Yes, do you understand the message?
How is your post related to the title (Error on the #!/bin/bash line?)
 
Old 11-14-2018, 12:41 PM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,806

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
You can store in an array
Code:
files=(*temp)
echo "in one row:"
echo "${files[@]}"
echo "on separate rows:"
printf "%s\n" "${files[@]}"
Or you can store in a simple variable, best in rows:
Code:
files=$(printf "%s\n" *temp)
echo "$files"
Or you use a loop; treating each file individually enables you to test them
Code:
for file in *temp
do
  [ -f "$file" ] || continue
  echo "$file"
done
If you want to append to a logfile, then
Code:
done >> logfile
(one open/close) is more efficient than
Code:
  echo "$file" >> logfile
(open/close) for each loop cycle.

Last edited by MadeInGermany; 11-14-2018 at 12:52 PM. Reason: Added loop example
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"bash: /usr/bin/git: No such file or directory " - why does bash look in /usr/bin babu198649 Linux - Newbie 9 04-24-2023 01:32 PM
Error: Cannot find 'ssh-keygen' in '/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin' venu.navat Linux - Software 3 03-08-2012 04:00 AM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM
sudo /usr/bin/chroot /home/chroot /bin/su - xxx| /bin/su: user xxx does not exist saavik Linux - General 3 07-04-2007 10:30 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration