Skip to main content
Edits for clarity as suggested from @Evan Morrison in the comments
Source Link
Toto
  • 18.3k
  • 73
  • 33
  • 45

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *"YOURSTRING"* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.


EDIT: Added "" around *YOURSTRING* for clarity

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *"YOURSTRING"* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.


EDIT: Added "" around *YOURSTRING* for clarity

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *"YOURSTRING"* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.

Edits for clarity as suggested from @Evan Morrison in the comments
Source Link

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *YOURSTRING**"YOURSTRING"* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.


EDIT: Added "" around *YOURSTRING* for clarity

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *YOURSTRING* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *"YOURSTRING"* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.


EDIT: Added "" around *YOURSTRING* for clarity

Rolled back to Revision 1 (with trivial improvements in wording and formatting) because Revision 2 was wrong.
Source Link

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$@""$*" == "your string"*YOURSTRING* ]]
then
    echo "YES"
else
    echo "NO"
fi

Note that the usage of $@, insteadThis takes advantage of $*, together with the fact that it is quoted, guarantees the flexibility in casespecial handling of a test string with whitespace. With $* only and bash super-test "your"[[ or "string"]] would be matched. There would be no difference, however, if there are no spacesbrackets.

See this explanation about the differences in the behavior.

This worked for me. It does exactly what you asked nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$@" == "your string" ]]
then
    echo "YES"
else
    echo "NO"
fi

Note that the usage of $@, instead of $*, together with the fact that it is quoted, guarantees the flexibility in case of a test string with whitespace. With $* only "your" or "string" would be matched. There would be no difference, however, if there are no spaces.

See this explanation about the differences in the behavior.

This worked for me. It does exactly what you asked and nothing more (no option processing). Whether that's good or bad is an exercise for the poster :)

if [[ "$*" == *YOURSTRING* ]]
then
    echo "YES"
else
    echo "NO"
fi

This takes advantage of special handling of $* and bash super-test [[]] brackets.

Fixed spelling.
Source Link
Loading
change $* to $@, explain reason and link to documentation.
Source Link
Loading
Source Link
Rich Homolka
  • 31.7k
  • 7
  • 55
  • 80
Loading