The simplest way to display file contents is using the cat
command:
cat file.txt
I can get the same result using input redirection:
cat < file.txt
Then, what is the difference between them?
The simplest way to display file contents is using the cat
command:
cat file.txt
I can get the same result using input redirection:
cat < file.txt
Then, what is the difference between them?
I am doing my homework and I have a question about one line. I don't understand what this >&2
means:
if test -d $2
then echo "$2: Is directory" >&2 ; exit 21
fi
I have this code that works:
# Hide irrelevant errors so chrome doesn't email us in cron
if [[ $fCron == true ]] ; then
google-chrome --headless --disable-gpu --dump-dom \
"$RobWebAddress" > "$DownloadName" 2>/dev/null
else
# Get silly error messages when running from terminal
google-chrome --headless --disable-gpu --dump-dom \
"$RobWebAddress" > "$DownloadName"
fi
If I try to shorten it like this:
# Hide irrelevant errors so chrome doesn't email us in cron
local HideErrors
[[ $fCron == true ]] && HideErrors="2>/dev/null"
google-chrome --headless --disable-gpu --dump-dom \
"$RobWebAddress" > "$DownloadName" "$HideErrors"
I get error messages:
[0826/043058.634775:ERROR:headless_shell.cc(597)] Open multiple tabs is only supported when remote debugging is enabled.
[0826/043058.672587:ERROR:headless_shell.cc(597)] Open multiple tabs is only supported when remote debugging is enabled.
[0826/043058.711640:ERROR:headless_shell.cc(597)] Open multiple tabs is only supported when remote debugging is enabled.
(... SNIP ...)
Why does a hard-coded argument work but not an argument as a variable?
Currently I found success with second answer's alternate suggestion:
# Redirect errors when cron is used to /dev/null to reduce emails
ErrorPipe=/dev/stderr
[[ $fCron == true ]] && ErrorPipe=/dev/null
google-chrome --headless --disable-gpu --dump-dom \
"$RobWebAddress" > "$DownloadName" 2>"$ErrorPipe"
Based on the first answer, I should point out program header already contains:
[[ $fCron != true ]] &&
exec 2> >(grep -v 'GtkDialog mapped without a transient parent' >&2)
Every time starting the machine, I run the following program:
$ cat start.sh
#! /bin/bash
google-chrome &> /dev/null &
lantern &> /dev/null &
xdg-open . &> /dev/null &
emacs &> /dev/null &
code ~/Programs/ &> /dev/null &
xdg-open ~/Reference/topic_regex.md &> /dev/null &
Cumbersome &> /dev/null &
...
How could I shorten the logic?
Oftentimes I run into small bash scripts that use this sort of syntax in if statements:
some command > /dev/null 2>&1
What is the purpose of outputting to /dev/null
like that, and what does the 2>&1
mean?
It always seems to work but I'd like to know what it's doing.