LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 10:00 AM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,316

Rep: Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905

Does the file with the actual name file.8 actually exist?
 
Old 02-09-2016, 10: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, 10:11 AM   #18
chewinghum
LQ Newbie
 
Registered: Feb 2016
Posts: 15

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

Rep: Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905
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, 10: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, 10: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, 10:34 AM   #22
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,316

Rep: Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905
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, 10: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, 10:48 AM   #24
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,316

Rep: Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905Reputation: 1905
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, 10: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, 10:59 AM   #26
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,737

Rep: Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877
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 11:04 AM.
 
Old 02-09-2016, 11:05 AM   #27
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,316

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


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

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

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