LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-09-2016, 09:00 AM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931

Does the file with the actual name file.8 actually exist?
 
Old 02-09-2016, 09:08 AM   #17
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
how is this possible to ignore a condition... if it's written wrong it should give an error or something...
 
Old 02-09-2016, 09:11 AM   #18
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
Yes, the file exists.
 
Old 02-09-2016, 09:14 AM   #19
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
linux is case sensitive. The name must match exactly for the statement to be true. I see nothing wrong with grail's code.
 
Old 02-09-2016, 09:14 AM   #20
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
should i post another question? cause now the loop is working, the problem is the ignored condition.
 
Old 02-09-2016, 09:24 AM   #21
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
this works:

Code:
[ "$1" == "z" ] && [ ! -z "$2" ]
this works too:

Code:
[[ "$1" == "z" && -n "$2" ]]
the loop works, but the last condition inside the loop is ignored.
 
Old 02-09-2016, 09:34 AM   #22
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
Quote:
Originally Posted by chewinghum View Post
should i post another question? cause now the loop is working, the problem is the ignored condition.
Nope, post your actual code. Just to make sure post the file name i.e the output of
ls -l file*
 
Old 02-09-2016, 09:40 AM   #23
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
You mean this below ? How can this help you ?

Quote:
[root@localhost scr]# ls -l scr
-rwxr-xr-x. 1 root root 1414 Feb 9 09:32 scr
 
Old 02-09-2016, 09:48 AM   #24
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
You indicated that file.8 exists but since linux is case sensitive I wanted you to make sure by posting the output of the ls command i.e.

ls -l file*
 
1 members found this post helpful.
Old 02-09-2016, 09:56 AM   #25
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
my god this is great. file did not exist. i really ment file-$no, not file.$no.
thanks a lot and sorry for the wasted time.
 
Old 02-09-2016, 09:59 AM   #26
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: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
off the top of my head -- check your quotes --
as soon as it finds a true match to a file whatever 'no' is then it will break, i don't know what the rest of your code looks like. but this is just an idea.

try your code but change this to
Code:
""file"."$no""

Code:
end=100

if [ "$1" == "z" ] && [ ! -z "$2" ] ; then

    while [[ "$no" < "$end" ]] ; do 
       echo "$no"
      if [[ -f ""file"."$no"" ]] ; then
          break
else
  (( no++ ))

done
	 
fi
never mind I just read that last post .. lol
mark solved thanks

Last edited by BW-userx; 02-09-2016 at 10:04 AM.
 
Old 02-09-2016, 10:05 AM   #27
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
No worries. You can mark the thread as solved using the thread tools pull down menu at the top.
 
  


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Working Expect script failing when placed inside bash Loop. Sigmaflux Linux - Newbie 1 01-27-2014 10:51 PM
[SOLVED] bash loop not working as expected... replica9000 Linux - Software 10 04-24-2011 09:08 AM
Bash for loop not working cryptinitedemon Linux - General 5 04-24-2010 10:44 AM
Bash loop using output of grep not working as needed Jim Pye Programming 7 01-16-2008 10:27 PM

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

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