LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   slightly confused about '!*' command (https://www.linuxquestions.org/questions/linux-newbie-8/slightly-confused-about-%27-%2A%27-command-4175646203/)

Reprovo 01-14-2019 02:09 PM

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

BW-userx 01-14-2019 03:20 PM

I've never seen that one before, this is what I found on the !
Bash Bang (!) commands

smallpond 01-14-2019 03:54 PM

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 '!'.

MadeInGermany 01-14-2019 05:07 PM

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 '!'*

Reprovo 01-14-2019 11:02 PM

Thank you all for the information! Clears things up.

Reprovo 01-14-2019 11:03 PM

Hi.

Thank you all for the information! clears things up.
Didn't know there were differences between interactive and non-interactive shell commands.

l0f4r0 01-15-2019 04:01 AM

Quote:

Originally Posted by BW-userx (Post 5949062)
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).

BW-userx 01-15-2019 07:43 AM

Quote:

Originally Posted by l0f4r0 (Post 5949283)
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

l0f4r0 01-15-2019 07:52 AM

^ 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 :D

BW-userx 01-15-2019 09:12 AM

Quote:

Originally Posted by l0f4r0 (Post 5949362)
^ 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 :D

well that's a relief, I can go back to resting easy. :D


All times are GMT -5. The time now is 08:48 AM.