LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-14-2019, 02:09 PM   #1
Reprovo
Member
 
Registered: Jul 2013
Posts: 50

Rep: Reputation: Disabled
slightly confused about '!*' command


Hi. I'm just going through some scripts at work just for learning purposes.

I'm a bit confused as to what the '!*' command is doing in the second line. What of the previous argument is it giving as output.
When i try to run similar commands and check what the output of '!*' is, it's printing everything after the initial '[[' which doesn't make sense here.

Code:
[[ "$enabled" == 1 ]] && echo "yes" >${FWRULES_DIR}/$RULEID/Enabled || echo "no" >${FWRULES_DIR}/$RULEID/Enabled


[[ "$ifacein" == !* ]] && echo "checked" >${FWRULES_DIR}/$RULEID/NotInput

Would appreciate any help in understanding the above.

Thanks
 
Old 01-14-2019, 03:20 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,082

Rep: Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903
I've never seen that one before, this is what I found on the !
Bash Bang (!) commands
 
1 members found this post helpful.
Old 01-14-2019, 03:54 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,194

Rep: Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857
The special meanings of "!" (history) and '*' (file globbing) would be disabled in this context. It looks like it will match any string whose first character is '!'.
 
Old 01-14-2019, 05:07 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,179

Rep: Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533
Yes, in the RHS of a [[ ]], in a non-interactive script, it matches a string that starts with a ! character.
In order to avoid an unwanted history substitution (for example when testing this in an interactive shell) I would quote the ! character: \!* or "!"* or '!'*

Last edited by MadeInGermany; 01-14-2019 at 05:09 PM.
 
Old 01-14-2019, 11:02 PM   #5
Reprovo
Member
 
Registered: Jul 2013
Posts: 50

Original Poster
Rep: Reputation: Disabled
Thank you all for the information! Clears things up.
 
Old 01-14-2019, 11:03 PM   #6
Reprovo
Member
 
Registered: Jul 2013
Posts: 50

Original Poster
Rep: Reputation: Disabled
Hi.

Thank you all for the information! clears things up.
Didn't know there were differences between interactive and non-interactive shell commands.
 
Old 01-15-2019, 04:01 AM   #7
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 852

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by BW-userx View Post
I've never seen that one before, this is what I found on the !
Bash Bang (!) commands
I don't agree with the explanation from this site:
Quote:
!* Run the previous command except for the last word
Actually, it's quite the opposite. In an interactive context, !* is a shortcut for !!:* which only retrieves all the arguments (i.e. parameter #>0) of the last command saved in history (not the command itself - i.e. parameter #0 - then)...

Example:
Code:
$ ls file1 file2
file1  file2
$ du -hc !*
du -hc file1 file2
8.0K    file1
8.0K    file2
16K     total
But indeed, as explained by smallpond and MadeInGermany, !* has a different meaning in a non-interactive context (! has no special meaning here, it's just a character).

Last edited by l0f4r0; 01-15-2019 at 04:03 AM.
 
1 members found this post helpful.
Old 01-15-2019, 07:43 AM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,082

Rep: Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903
Quote:
Originally Posted by l0f4r0 View Post
I don't agree with the explanation from this site:

Actually, it's quite the opposite. In an interactive context, !* is a shortcut for !!:* which only retrieves all the arguments (i.e. parameter #>0) of the last command saved in history (not the command itself - i.e. parameter #0 - then)...

Example:
Code:
$ ls file1 file2
file1  file2
$ du -hc !*
du -hc file1 file2
8.0K    file1
8.0K    file2
16K     total
But indeed, as explained by smallpond and MadeInGermany, !* has a different meaning in a non-interactive context (! has no special meaning here, it's just a character).
don't kill the messenger, I just posted what I seen on it, not test it, it is still Greek to me, besides the point.

I've never seen it == !* used in any context, so I just googled on it "! bash" and got what I posted.

I do not know who names there files with a leading !
it does not look like it is seeking inside of a file for a comment that starts with !

Interactive and non-interactive shells and scripts

Last edited by BW-userx; 01-15-2019 at 07:58 AM.
 
Old 01-15-2019, 07:52 AM   #9
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 852

Rep: Reputation: 286Reputation: 286Reputation: 286
^ lol. I didn't say that I didn't agree with something you directly said BW-userx but only with the resource you have posted. No worries
I'm not Leonidas in movie 300 (https://www.youtube.com/watch?v=514IEcgz1Q8), I don't kill messengers

Last edited by l0f4r0; 01-15-2019 at 07:55 AM.
 
Old 01-15-2019, 09:12 AM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,082

Rep: Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903
Quote:
Originally Posted by l0f4r0 View Post
^ lol. I didn't say that I didn't agree with something you directly said BW-userx but only with the resource you have posted. No worries
I'm not Leonidas in movie 300 (https://www.youtube.com/watch?v=514IEcgz1Q8), I don't kill messengers
well that's a relief, I can go back to resting easy.
 
  


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
Debian: Low LAN speed and slightly confused server jo4 Debian 4 04-17-2008 12:00 PM
Confused nay Very Confused chrystlenight SUSE / openSUSE 3 08-28-2007 05:57 PM
Hiding IP in IRC (Slightly OT) R4z0r Linux - Networking 2 06-21-2003 12:50 PM
2 slightly off topic questions case1984 Linux - General 2 02-15-2003 04:59 PM
Slightly off topic, but... Stephanie General 11 01-14-2002 09:34 AM

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

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