Introduction
Here strings let you send a small piece of text as input to a command easily, without creating a file.
command <<< "string"wc -w <<< "hello world"grep 'apple' <<< "apple banana cherry"
read line <<< "This is a line"; echo "$line"
#!/bin/bash # Count words in a string using here string word_count=$(wc -w <<< "one two three four") echo "Word count: $word_count" # Search for a word in a string if grep -q 'cat' <<< "dog cat mouse"; then echo "Found cat" else echo "Cat not found" fi
<<< do in bash scripting?<<< to send a short string directly as input to a command without needing a file.cat command?<<< followed by a quoted string to preserve spaces or special characters.cat <<<"hello world".grep 'world' <<< "hello world"
read name <<
read and does not require quotes for simple alphanumeric strings like John.read name << correctly sets name=John (even with literal \n if present), and echo "Name is $name" outputs correctly. No syntax or runtime errors.line. Which command correctly uses a here string to do this?line.$line to grep with -o (outputs each match on a new line), then counts lines with wc -l, correctly counting occurrences.Pass the test and this pattern moves unknown