Skip to main content
20 events
when toggle format what by license comment
Apr 26 at 8:17 comment added Convexity if [[ " $* " == *" YOURSTRING "* ]] excludes false positives (requires that YOURSTRING has spaces around it)?
Aug 5, 2023 at 15:56 comment added 16851556 Interesting is that asterisks seems to be necessary. Without it, it not worked for me. Any logical explanation to remember this? Can edit answer to explain this?
Mar 26, 2022 at 8:49 comment added Frank N I add spaces to the param string and to the matching term wanted, to make sure, it's not a partial match of another parameter (like "format" as part of "noformat" for example). [[ ! " $@ " =~ [[:space:]]foo[[:space:]] ]] && echo "do something"
S Mar 18, 2022 at 11:45 history edited Toto CC BY-SA 4.0
Edits for clarity as suggested from @Evan Morrison in the comments
S Mar 18, 2022 at 11:45 history suggested Bysander CC BY-SA 4.0
Edits for clarity as suggested from @Evan Morrison in the comments
Mar 18, 2022 at 9:27 review Suggested edits
S Mar 18, 2022 at 11:45
Jan 19, 2022 at 16:49 review Suggested edits
Jan 19, 2022 at 18:02
Mar 23, 2021 at 4:52 comment added Evan Morrison This didn't work until i read @velis comment and realized the YOURSTRING needs those asterisks. Maybe edit answer for clarity?
Jun 28, 2019 at 7:20 comment added velis Note for noobs like me: the YOURSTRING might be quoted, but the asterisks must be OUTSIDE the quotes, e.g. if [[ "$*" == *"my search string"* ]]
May 22, 2019 at 19:46 comment added Scott - Слава Україні This answer has been wrong for the past four years because h7r’s edit broke it.  The original answer (which I have now restored) works, provided “your string” contains no glob characters, and with some false positives.  For example, if the command is create a new certificate and “your string” is cat, this will report a match because certificate contains cat.
May 22, 2019 at 19:45 history edited Scott - Слава Україні CC BY-SA 4.0
Rolled back to Revision 1 (with trivial improvements in wording and formatting) because Revision 2 was wrong.
May 22, 2019 at 19:38 history edited Scott - Слава Україні CC BY-SA 4.0
Fixed spelling.
May 22, 2019 at 10:19 review Suggested edits
May 22, 2019 at 18:00
Dec 19, 2016 at 20:23 comment added starfry This compares the entire argument list with your string. I think you need to do what is suggested by this answer. i.e: bash -c 'echo args=$*; for i in "$@" ; do [[ $i == "bar" ]] && echo "Is set!" && break ; done' -- bar foo would work.
Nov 4, 2015 at 11:55 comment added Tobia Not working. bash -c 'echo args=$*; [[ "$@" == "bar" ]] && echo YES || echo NO' -- foo bar
Jul 14, 2015 at 8:37 comment added Seppo Enarvi Did you mean to use the =~ operator? Otherwise I don't see why this should work, and indeed it doesn't work when I try the exact script.
S Feb 1, 2015 at 14:24 history suggested h7r CC BY-SA 3.0
change $* to $@, explain reason and link to documentation.
Feb 1, 2015 at 12:55 review Suggested edits
S Feb 1, 2015 at 14:24
Feb 1, 2015 at 12:51 comment added h7r IMHO this had to be the most correct answer, since the question requires only to check the presence of a parameter. I have edited, however, changing $* to $@, since the to-be-tested string might have spaces and added link to bash's documentation about it.
Sep 8, 2010 at 21:03 history answered Rich Homolka CC BY-SA 2.5