LinuxQuestions.org
Review your favorite Linux distribution.
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 03-02-2017, 11:33 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
bash: Another script problem (Didn't take long, did it?)


Non-working code:
Code:
megic=0
tragic=0
while read file0
do
logic=$((tragic+1))
Shellcheck return:
Code:
logic=$((tragic+1))
^-- SC2034: logic appears unused. Verify it or export it.
In a very similar script:
Code:
while read item
do
wilde1=$((yeats+1))
#Likewise
file0=$item
Shellcheck returns no errors. Why? In script 1, logic is used for the first time and defined by the +1 incrementor, as is wilde1 in the second. Why should it work in one but not in the other? (Full scripts are attached, before anyone complains they don't have the code.)

Carver
Attached Files
File Type: txt checksource.txt (702 Bytes, 25 views)
File Type: txt checkwriter.txt (693 Bytes, 24 views)

Last edited by L_Carver; 03-02-2017 at 11:40 PM.
 
Old 03-03-2017, 05:23 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,691

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Look at the two scripts.

In the checkwriter script yeats is used as a loop counter which counts how many files are checked i.e. yeats=$((yeats+1)) and keats counts how many files have a writer tag. wilde1 is also a loop counter and incremented since yeats changes.

In the first script checksource you do not have a loop counter (yeats) nor a if true counter (keats). tragic is never used nor incremented so logic=$((tragic+1)) is always 1. megic is never incremented and I assume it is supposed to count the number of has-xmpsource.txt files.

Last edited by michaelk; 03-03-2017 at 05:38 AM.
 
1 members found this post helpful.
Old 03-03-2017, 06:28 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
logic is set in the first script, but not used anywhere (=logic appears unused), so there is no reason to set it.
wilde1 is set the same way, and it is used later.... (echo "Checking file #$wilde1, $item")
 
1 members found this post helpful.
Old 03-03-2017, 09:27 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Many thanks, pan64

I didn't see where logic wasn't being incremented.

+1 to michaelk as well.

Carver
 
  


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 script-how can user choose how long to run it for? rmcateer Programming 3 02-23-2015 09:10 PM
[SOLVED] Bash/Sed : Long time (seconds) between print of last line and script termination sumncguy Linux - Newbie 2 11-04-2014 07:04 AM
How can I extract the .rpm filename from long list of entries using bash shell script Glenn D. Linux - Software 2 07-14-2012 05:42 AM
Little bash script and file to give long (or any) directories short names WardXmodem Programming 1 11-23-2009 12:24 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM

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

All times are GMT -5. The time now is 02:23 AM.

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