LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-03-2017, 12:33 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

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, 23 views)
File Type: txt checkwriter.txt (693 Bytes, 17 views)

Last edited by L_Carver; 03-03-2017 at 12:40 AM.
 
Old 03-03-2017, 06:23 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,549

Rep: Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144Reputation: 3144
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 06:38 AM.
 
1 members found this post helpful.
Old 03-03-2017, 07:28 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,603

Rep: Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361
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, 10:27 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

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


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
bash script-how can user choose how long to run it for? rmcateer Programming 3 02-23-2015 10:10 PM
[SOLVED] Bash/Sed : Long time (seconds) between print of last line and script termination sumncguy Linux - Newbie 2 11-04-2014 08: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 06:42 AM
Little bash script and file to give long (or any) directories short names WardXmodem Programming 1 11-23-2009 01:24 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM

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

All times are GMT -5. The time now is 04:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration