LinuxQuestions.org
Visit Jeremy's Blog.
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 05-23-2017, 05:45 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Script with readline gives 2 different answers same variable


I'm using the newer command, mapfile, but the principle is the same (see my thread about "lost command line options" or something of that sort).

The script:
Code:
#!/bin/bash

mapfile -t lalaland <alleylocate
file0=${lalaland[0]}
echo $file0
city=${lalaland[1]}
echo $city
sprov=$(echo ${lalaland=[2]})
echo "State is $sprov"

echo ${lalaland[2]}
exit 1
country=${lalaland[3]}
echo $country
ccode=${lalaland[4]}
echo $ccode
exiftool -fast5 -overwrite_original_in_place -P -q -City="$city" -State="$sprov" -Country="$country" -CountryCode="$ccode" "$file0"

exit 0
When run on the attached text file, sprov and lalaland[3] give different answers. The first consistently returns the file name [array item 0] while echoing lalaland3 returns the proper array item (California, in this case).

But it's the 0 line (filename) that's written as "State" by exiftool, and of course I don't want or need that. Am I missing something? Is something out of order?

Carver
PS:The name of the attached file was changed to comply with LQ's file validity requirements. When I run the script I use the same text file without the DOS extension, as it appears in the script
Attached Files
File Type: txt alleylocate.txt (54 Bytes, 9 views)

Last edited by L_Carver; 05-23-2017 at 05:47 PM. Reason: Clarified extension on attachment (not present in the script)
 
Old 05-23-2017, 05:57 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Ok, perhaps I don't understand this, but:

(i) In your description, surely you mean lalaland[2] (the state), not lalaland[3] (the country).

(ii) What is that second '=' sign doing in sprov=$(echo ${lalaland=[2]})?

(iii) Why are you assigning sprov anyway? Why aren't you just using state=${lalaland[2]} like the other array elements?
 
Old 05-23-2017, 07:43 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243Reputation: 2243
first mention is this
Code:
sprov=$(echo ${lalaland=[2]})
= <----- not suppose to be there

yeapers looks like the above got'er figured out. I was just reading yours. At first. That MAPFILE got my attention.

script
Code:
#!/bin/bash

mapfile -t lalaland <alleylocate
file0=${lalaland[0]}
echo $file0
city=${lalaland[1]}
echo $city
sprov=${lalaland[2]}
echo "State is $sprov"

echo ${lalaland[2]}
exit 1
country=${lalaland[3]}
echo $country
ccode=${lalaland[4]}
echo $ccode
exiftool -fast5 -overwrite_original_in_place -P -q -City="$city" -State="$sprov" -Country="$country" -CountryCode="$ccode" "$file0"

exit 0
Code:
userx%slackwhere ⚡ testing ⚡> ./MapFile alleylocate
858_1000.jpg
Los Angeles
State is California
California

Last edited by BW-userx; 05-23-2017 at 09:44 PM.
 
Old 05-25-2017, 08:37 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Smile Fixed it (following the helps) and it worked.

Which is good, because it gives me something besides the ordinary "Location/Sub-location" fields to which I can add location information. Ordinarily I use those for places like "Beach" or "Home," "Sidewalk or "Driveway."

Thanks again for all the help.

Carver
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Patch for readline.SlackBuild to include rlfe (ReadLine Fron-End) tfonz Slackware 0 10-22-2016 12:45 PM
[SOLVED] Bash script: How to assign variable to an sqlite3 command with variable embedded? ninja6o4 Linux - Software 10 02-15-2015 05:43 PM
Readline variable horizontal-scroll-mode. stf92 Slackware 3 10-21-2013 09:34 PM
Push output string from script directly into bash / readline command input buffer GreyBeard Linux - Software 3 02-21-2012 12:26 AM
Need help with script writing: Storing cmd in variable, print variable, then exe cmds Arodef Programming 3 01-17-2012 01:26 AM

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

All times are GMT -5. The time now is 04:12 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