How to tell which parameter is being supplied to a command with a redirectioin operator?
You are using two different things here and should be using a third. Let's see:
-
|
: This is the pipe operator, it serves to pass the output of one process as input to another:foo | bar
This runs the program
foo
and passes its output as input to the programbar
. -
>
,<
,>>
and<<
: These are the redirection operators, they serve to send data to/from files:foo > bar
: runs the programfoo
and saves its output to the filebar
, overwriting1 its contents and creating it if it does not exist.foo >> bar
: runs the programfoo
and saves its output to the filebar
, appending to its contents and creating it if it does not exist.foo < bar
: runsfoo
, telling it to read input from the filebar
.-
The
<<
is a special case, since there is no point in "appending" input to a command, the<<
is primarily (exclusively AFAIK) used for Here Documents:$ cat << EOF > file.txt > Hello World! > EOF
The construct
<< SomeStringHere > Out.file
will redirect all text written until it encounters the ending string (EOF
in the example above) to the target file. Here docs allow you to easily format multi-line strings and include variables and special characters.
-
The
<<<
operator, the Here String, is like a Here Document but it expands variables. So, for example:grep foo <<< "$bar"
The command above is equivalent to
echo "$bar" | grep foo
. -
What you are actually looking for is called process substitution and is another way to pass the output of a command to another. It consists of
<(command)
.foo <(bar)
So, for your
at
example, you could doat now < <(echo "notify-send HELLO")
The above works because process substitution actually creates a file (read the link above for more details) and it is the file descriptor of that file that is passed with
<
toat now
.
1 The default behavior is to overwrite, this can be modified by setting the noclobber
option to bash. If set, echo foo > bar
will fail if bar
exists. In that case, it can be forced using echo foo |> bar
instead. See section 3.6.2 here.
In this case, echo "notify-send HELLO"
is a process not a file - so you need a process substitution rather than a file redirection
at now < <(echo "notify-send HELLO")
You could also have used a here string to avoid the echo
command entirely
at now <<< "notify-send HELLO"