LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-23-2018, 02:40 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,918

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318

I can't suggest you anything else but go to www.shellcheck.net and check your script. It will tell you ...
Also please use code tags instead of quote (probably you can still edit your last post)
 
Old 10-23-2018, 03:27 AM   #17
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,806

Rep: Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206
Good idea! shellcheck shows the mistake:
^-- SC2076: Don't quote rhs of =~, it'll match literally rather than as a regex.
The right hand side must not be in quotes.

Note: [[ ]] does not do globbing, in contrast to [ ] (that's why there cannot be a =~ operator in [ ], and there shouldn't be a == operator - well bash allows it but treats it like the = operator)

What is the ?: for - allowing a preceding ? or : ??
Suggestion: first check the allowed characters then the range
Code:
if [[ $uservar =~ ^[0-9]+$ ]] && [[ $uservar -le 10 ]]
then
...
 
Old 10-23-2018, 04:01 AM   #18
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by MadeInGermany View Post
What is the ?: for - allowing a preceding ? or : ??
I think this is for not-capturing group
 
  


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
cat command inside foreach loop not working Praveen waliitagi Linux - Newbie 6 10-17-2013 02:09 AM
Sleep inside for loop inside while loop causing issues. TheOnlyQ Programming 13 12-19-2012 12:59 PM
How to use a command inside sed ZAMO Linux - General 3 02-27-2009 04:37 AM
Bash: command works but not inside of for loop. RijilV Programming 3 05-21-2006 08:29 PM

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

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