The simple answer is it gives you a root shell. That's what it's being used for here. There's a good technical comparison between the su
, sudo -i
, sudo -s
and sudo su
methods on Unix.SE but that's really not relevant here. The code could have used any and would have worked.
The help nugget means a few things:
It's looking for a command in the $SHELL
environment variable. If you run echo $SHELL
you'll probably see /bin/bash
. That means you'll get a root instance of Bash. I'm sure if you were in zsh
it would mean you get a root instance of zsh
.
If $SHELL
is empty, it falls back to the default shell defined in /etc/passwd
for that user.
If you provide a command (eg sudo -s whoami
), it's actually running: sudo /bin/bash -c "whoami"
If you don't pass a command, it doesn't pass a -c
argument over so you just get an interactive shell.
I've used the phrase "root" several times. By default sudo
is all about running things as root but sudo
(and su) can run things as other users (if you have permission to do so). I'm only stating this for the pedants who will cry out that sudo -s -u $USER
doesn't give them a root shell as I promised -s
would above.
And in my humblest of opinions, it's really silly to become root for just two commands, not to mention that it could leave a user accidentally running further commands as root. If you want or need to run something as root, just premend the command with sudo
:
sudo apt-get update
sudo apt-get install -y build-essential libtool libcurl4-openssl-dev libncurses5-dev libudev-dev autoconf automake screen
I'd be dubious of any tutorial that suggested getting a root shell, except in the cases where you do have bucketloads of commands to run... And even then, there's scripting.
There are multiple levels of quoting/escaping going on here. First, you have your FS
regex (-F "[\\[\\]\:\)\(]"
) in double quotes. That's what's giving the warnings:
$ awk -F"[\\[\\]:)(]" '{print $2}' file
awk: warning: escape sequence `\[' treated as plain `['
awk: warning: escape sequence `\]' treated as plain `]'
awk: fatal: :, [., or [=: /[[]:)(]/
While single quotes just work:
$ awk -F'[\\[\\]:)(]' '{print $2}' file
field#13
That's because anything in double quotes is first expanded by the shell. So, the shell first expands \\[
to \[
and then passes it to awk. You can see this happening with set -x
:
$ set -x
$ awk -F"[\\[\\]:)(]" '{print $2}' file
+ awk '-F[\[\]:)(]' '{print $2}' file
As you can see above, the shell ate the first escape. So don't use "
here at all.
The next issue is that awk itself interprets the escapes twice. Because the -F
can accept special escapes like \t
and \r
etc, it will first try to read \[
as a single, escaped character. Since \[
is the same as [
(unlike, say \n
which is not the same as n
since \n
is a newline), it gives you a warning message, explaining that it treated \[
as [
.
So, you need the first escape to escape the \
itself, and the second escape to escape the [
. In other words, in \\[
, the 1st \
is escaping the second \
so that what awk
finally receives is \[
.
It might be easier to understand if you consider something like this:
$ echo -e 'a\tb'
a b ## prints a tab character
$ echo -e 'a\\tb'
a\tb ## prints a literal \t
$ echo -e "a\\tb"
a b ## prints a tab because of the double quotes
$ echo -e "a\\\tb"
a\tb ## 3ple escaping! Prints a literal `\t` again.
The last example above is the most telling. Since the string to be echoed is in double quotes, it is expanded by the shell first (that eats one \
), then by echo -e
(that eats another \
) and is finally printed as a literal \t
.
Best Answer
at
reads commands from standard input, or from a file if you specify the-f
flag. Whatsh t.sh | at [time]
does is:But the script has no output, so there is nothing to execute on Sunday.
What you want is
at 03:13Jun15 -f t.sh
.