LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2020, 11:35 PM   #1
blason
Member
 
Registered: Feb 2016
Posts: 103

Rep: Reputation: Disabled
Can someone please help me understanding this variable?


Hi Team,

I am going through one of the bash script and stuck on this variable. I am not sure what exactly is trying to interpret and how can that be used later on?

${_ip:0:1} != "#"

TIA
blason R
 
Old 06-26-2020, 11:40 PM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,845
Blog Entries: 3

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
It looks like use of parameter substitution
 
1 members found this post helpful.
Old 06-27-2020, 12:31 AM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: Currently: openSUSE, Raspbian, Slackware. Formerly: CentOS, MacOS, Red Hat. Other: Solaris, Tru64
Posts: 1,942

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by blason View Post
Hi Team,

I am going through one of the bash script and stuck on this variable. I am not sure what exactly is trying to interpret and how can that be used later on?

${_ip:0:1} != "#"

TIA
blason R
It almost looks like a test to check that the first character is not a pound sign. Perhaps part of some filtering to continue processing only the lines in a file that aren't commented out?

I'm guessing that this is part of an if-then statement. Can you post a little bit more of the script for context?


HTH...
 
1 members found this post helpful.
Old 06-27-2020, 04:45 AM   #4
fatmac
Senior Member
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Posts: 3,644

Rep: Reputation: Disabled
If I'm not mistaken, there is no pound sign (), the equation does not equal (!=) out to a hash/number sign (#).

(But it has been several years since I involved myself with more than simple one liner scripts.)
 
Old 06-27-2020, 07:05 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,398

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
Some say pound:
Wikipedia about the # sign

The code is used in a test, mostly in [ ] or [[ ]]
Code:
[[ ${_ip:0:1} != "#" ]] && echo "not a #comment"
An equivalent code is
Code:
[[ $_ip != "#"* ]] && echo "not a #comment"

Last edited by MadeInGermany; 06-27-2020 at 07:07 AM.
 
Old 06-27-2020, 07:29 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 14,663

Rep: Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777
$_ip is a variable and ${_ip:0:1} is:
Quote:
${parameter:offset:length} Substring Expansion.
see man bash about details
Otherwise ${_ip:0:1} != "#" itself is incomplete (and useless), it is only part of an expression as it was explained (see man bash and conditional expressions).
 
1 members found this post helpful.
Old 07-01-2020, 03:18 AM   #7
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,758

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
Lightbulb

Quote:
Originally Posted by pan64 View Post
$_ip is a variable and ${_ip:0:1} is:
see man bash about details
Otherwise ${_ip:0:1} != "#" itself is incomplete (and useless), it is only part of an expression as it was explained (see man bash and conditional expressions).
Agree with Pan64 it is just part of an expression.

This link, explains about positional parameters and parameters expansion.

if only one line is shown by OP then it will be very hard to explain on how the statement works as part of the whole script.
 
1 members found this post helpful.
  


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
can't someone help me i'am trying to install idevicerestore and when i do the sudo make i get this error can someone help me please shawn7226791 Linux - Software 4 09-18-2019 07:25 AM
[SOLVED] Help with understanding the 'with' keyword and understanding file reading and writing. vysero Programming 3 05-30-2018 02:37 PM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 12:08 AM
Help understanding auth.log entries someone trying root access? jimdaworm Linux - Security 4 12-16-2008 03:27 AM
can someone please help me with installing Linux Doom please??? ttaylor Linux - General 5 12-25-2001 04:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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