LinuxQuestions.org
Visit Jeremy's Blog.
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 12-23-2016, 05:06 AM   #1
P.G.Krish
Member
 
Registered: Jun 2016
Distribution: Ubuntu
Posts: 64

Rep: Reputation: Disabled
Question bash ${1#*@} Meaning?


Quote:
${1#*@}
-
i saw this from shell script, I want to understand what It means? I searched google , They returns nothing. Do u have any idea
 
Old 12-23-2016, 05:45 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,886
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by P.G.Krish View Post
${1#*@}
i saw this from shell script, I want to understand what It means? I searched google , They returns nothing. Do u have any idea
The ${ term } portion means "term" used as a command, for example:
Code:
~ abc=ls
~ ${abc}
.     ..     1.txt     2.txt
The ${abc} cause a substitution of the symbol abc with what that symbol is assigned too.

1#*@ appears to be some form of weird regular expression, or it is a variable symbol which has already been set up within this script.

The couple of things you can do are to:
  1. Post more of this script leading up to this point and especially all references to this symbol or variable
  2. Insert a "set -xv" into the script and run it and observe what happens.
  3. Insert some "echo ${1#*@}" lines into the script to cause an echo of what this variable or symbol represents.
If this turns out to be a very poorly named variable, then it is a very bad script.

In regular expressions asterisk * means "1 or more times", unsure what @ means, if anything. Someone more well versed in regex may know more. To me this statement is nonsense and if it is really the script authors "cute" variable name, it is a bad variable name. My point there being that while people can write "legally correct syntax", it does not mean they should try to write obtuse code that other people cannot properly interpret.
 
1 members found this post helpful.
Old 12-23-2016, 05:49 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,390
Blog Entries: 3

Rep: Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776Reputation: 3776
That is parameter expansion and works similar to regular expressions. That one in particular finds and erases everything in the given variable up to and including the @. The given variable is the first second positional parameter aka $1 aka ${1}

Last edited by Turbocapitalist; 12-23-2016 at 05:53 AM. Reason: off by one
 
1 members found this post helpful.
Old 12-23-2016, 05:55 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,837

Rep: Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971Reputation: 5971
In addition,

Deletes the shortest match of substring from front of $string. In this example the $string is $1 which is the first command line argument. The substring to match is *@ or everything from the front of the string to the first @

example:

#!/bin/bash
echo ${1#*@}

myscript user@gmail.com would output gmail.com

http://www.tldp.org/LDP/abs/html/str...ipulation.html

Last edited by michaelk; 12-23-2016 at 06:07 AM.
 
2 members found this post helpful.
  


Reply

Tags
bash, shell scripting


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
[SOLVED] Meaning of parameters in bash function: eval, $@, $# gacanepa Linux - Newbie 6 04-11-2013 05:56 PM
Meaning of backslash in bash within here document and command substitution moraxu Linux - Newbie 2 04-02-2013 12:51 PM
What are the meaning and the relevance of #!/bin/bash? ravi_nandula Linux - Newbie 9 03-29-2012 07:31 AM
meaning of if [ -z $SOMETHING....] in bash shell darwinianlo Linux - Newbie 8 08-09-2007 11:02 AM
Meaning of -R, --g, -G shipon_97 Linux - Newbie 1 11-23-2006 11:02 AM

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

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