[[ $list =~ (^|[[:space:]])$x($|[[:space:]]) ]] && echo 'yes' || echo 'no'
or create a function:
contains() {
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]] && exit(0) || exit(1)
}
to use it:
contains aList anItem
echo $? # 0: match, 1: failed
More Related Contents:
- How to read a file line by line and making a new file for each line having same filename as last word of each line? [closed]
- Why to code a script which will check if some package is installed in linux and if not then install it?
- How to permanently set $PATH on Linux/Unix [closed]
- How do I use sudo to redirect output to a location I don’t have permission to write to? [closed]
- Aborting a shell script if any command returns a non-zero value
- Bash ignoring error for a particular command
- How to replace spaces in file names using a bash script
- How can I quickly sum all numbers in a file?
- Bash script process substitution Syntax error: “(” unexpected
- Setting environment variables in Linux using Bash
- Get the Perl rename utility instead of the built-in rename
- Run a shell command when a file is added
- extracting unique values between 2 sets/files
- Linux non-blocking fifo (on demand logging)
- Pattern match does not work in bash script
- How do you normalize a file path in Bash?
- Pipe only STDERR through a filter
- How to determine SSL cert expiration date from a PEM encoded certificate?
- Extract one word after a specific word on the same line [duplicate]
- How to run a script at a certain time on Linux? [closed]
- How do I remove newlines from a text file?
- Error “syntax error near unexpected token ‘(‘” in Bash script when selecting files
- How to copy a file to multiple directories using the gnu cp command
- Linux: remove file extensions for multiple files
- Joining multiple fields in text files on Unix
- BASH copy all files except one
- How to show line number when executing bash script
- Using awk to count the number of occurrences of a word in a column
- Add a newline only if it doesn’t exist
- How can I split one text file into multiple *.txt files?