time command1 | command2   Does time apply to command1 or command1 | command2?  If your answer is  one of the two, how would you specify the other?  Could you explain your answer based on the grammar of bash or how the shell interprets the command?  When the shell parses the command, does it recognize time as a reserved word before recognizing | as a control operator? Does the order between  recognizing time as a reserved word and recognizing | as a control operator determines whether time applies to command1 or command1 | command2?   Thanks.
121860
I want to time a command which consists of two separate commands with one piping output to another. For example, consider the two scripts below:  $ cat foo.sh #!/bin/sh sleep 4  $ cat bar.sh #!/bin/sh sleep 2   Now, how can I get time to report the time taken by foo.sh | bar.sh (and yes, I know the pipe makes no sense here, but this is just an example)? It does work as expected if I run them sequentially in a subshell without piping:  $ time ( foo.sh; bar.sh )  real    0m6.020s user    0m0.010s sys     0m0.003s   But I can't get it to work when piping:  $ time ( foo.sh | bar.sh )  real    0m4.009s user    0m0.007s sys     0m0.003s  $ time ( { foo.sh | bar.sh; } )  real    0m4.008s user    0m0.007s sys     0m0.000s  $ time sh -c "foo.sh | bar.sh "  real    0m4.006s user    0m0.000s sys     0m0.000s   I've read through a similar question () and also tried the standalone time executable:  $ /usr/bin/time -p sh -c "foo.sh | bar.sh" real 4.01 user 0.00 sys 0.00   It doesn't even work if I create a third script which only runs the pipe:  $ cat baz.sh #!/bin/sh foo.sh | bar.sh   And then time that:  $ time baz.sh  real    0m4.009s user    0m0.003s sys     0m0.000s   Interestingly, it doesn't appear as though time exits as soon as the first command is done. If I change bar.sh to:  #!/bin/sh sleep 2 seq 1 5   And then time again, I was expecting the time output to be printed before the seq but it isn't:  $ time ( { foo.sh | bar.sh; } ) 1 2 3 4 5  real    0m4.005s user    0m0.003s sys     0m0.000s   Looks like time doesn't count the time it took to execute bar.sh despite waiting for it to finish before printing its report1.  All tests were run on an Arch system and using bash 4.4.12(1)-release. I can only use bash for the project this is a part of so even if zsh or some other powerful shell can get around it, that won't be a viable solution for me.  So, how can I get the time a set of piped commands took to run? And, while we're at it, why doesn't it work? It looks like time immediately exits as soon as the first command has finished. Why?   I know I can get the individual times with something like this:  ( time foo.sh ) 2&gt;foo.time | ( time bar.sh ) 2&gt; bar.time   But I still would like to know if it's possible to time the whole thing as a single operation.     1 This doesn't seem to be a buffer issue, I tried running the scripts with unbuffered and stdbuf -i0 -o0 -e0 and the numbers were still printed before the time output.
82471
I've installed a version of Ubuntu Server and although I'm fairly still fresh with Ubuntu, I'm trying to create a bash file to run a program in the background. More importantly, I'm trying to get a file nameto display correct and create it before I start running the program (I like my debug stuff).  However, here is my bash script:    #!/bin/bash  PATH="/var/log/servers/Game/"  FILENAME="startup"  EXT=".log"  DATE=$(date +%d-%m-%Y)  NEWFILE=${PATH}${FILENAME}_${DATE}${EXT}   I have verified that the file does exist in the PATH directory. However, the issue is with the date command. When I run the script bash -x game.sh this is what is displays.   + PATH=/var/log/servers/Game/  + FILENAME=startup  + EXT=.log  ++ date +%d-%m-%Y  game.sh: line 5: date: command not found  + DATE=  + NEWFILE=/var/log/servers/Game/startup_.log  + echo /var/log/servers/Game/startup_.log   I don't understand why it would say the command doesn't work, when I can go to the main console and run date and get a valid response.  Any help is greatly appreciated!
91016
Often when I mistype a command such as ls (e.g. I hit ENTER before I type 's') there is a long (~2s) delay after the terminal displays:  bash: l: command not found...   I can understand the reasons for a similar delay after an incorrect password is entered, per . But why delay after an unrecognized command? Does FAIL_DELAY in /etc/login.defs affect this also?
21593
When you drop to the terminal via Applications -&gt; Terminal or Ctrl+Alt+F1 etc. bash is used by default to interpret your commands. If you wish to use another command interpreter (like zsh or fish), how do you get this to start as default?
88167
I have come across several commands that use 2&gt;&amp;1 and 1&gt;&amp;2, but I quite can't get my head around the purpose of using it and when I should be using it.  What I understand  I know that 1 represents standard out and 2 represents standard error. I understand that 2&gt;&amp;1 combines the output of 2 to 1 and vice versa.  What I don't get   When should I be using it? What purpose does it serve?
107478
If I time a process using the time command, I get output for 'real', 'user', and 'sys'.  My understanding from  is that 'real' is wall time, whereas 'user' and 'sys' are process time.  Does this imply that 'user' and 'sys' will be unaffected by other processes? In other words, if the computer is under heavy load or light load from other processes, it may take more time on the wall clock ('real') to finish my process. But my process may have only required 5 seconds of running time, even though it was spread out over 20 seconds of real-world time.  Am I guaranteed that I'll be told '5 seconds user time' regardless of whatever else the system is doing?
17675
I used   history | less   to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did  !22   at the command prompt and it worked -- executing the set of commands on the line I did at that time. I cannot figure out where the exclamation mark is used, what does it represent in terms of actions taken by bash, and where to use it. From the documentation I do not see an explanation that is 'tangible'.
38685
So I've read a few times about this, the “moving arguments” and all that. But what does it really mean? Could someone explain in a few words what is going on at the TeX level, what is the difference between these two kinds of commands? Furthermore, when do we need to use \protect and why?
31975
What can explain the examples below and how do I fix this, preferably without heavy quoting acrobatics? I am using the $n to simulate multiple line command strings, just in case it distracts you from the real question.  ~$ n=$'\n'; sudo -i echo "line1${n}line2${n}" line1line2 ~$   but  ~$ n=$'\n'; sudo echo "line1${n}line2${n}" line1 line2  ~$
15211
Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?  Bottom-Line: Execution time in the Bash history
10766
Can I make a bash command line that only runs a certain command if the process is not already running (in the background)?  How do I check*, if a command is already running?  (so I can add the next command with &amp;&amp; in between them so the next one only executes if the first one is true).  *: test, determine, discover, find out
64463
So, when a command is not found, by what means is the "did you mean:" list populated? What program finds these alternate commands?  What is the meaning of: "(main), (universe)..."? Can I change which program finds these?
114750
I'm searching for the possibility to execute a shell script or command based on idle time in the bash shell.  As an example, if I'm in a SSH session to a server of mine and after X minutes of inactivity in the terminal, I want a command to start a desired program like cmatrix, and when I come back and press a key I will get back where I left.
20273
As a primarily Java programmer, I find the bash if-then construct quite confusing, especially regarding whitespace. Can anyone explain why the first one works, but not the second or third?  #works if [ -n $1 ]; then echo "parameterized"; fi  #output: ./links: Zeile 1: [-n: Kommando nicht gefunden. if [-n $1 ]; then echo "parameterized"; fi  #output: ./links: Zeile 1: [: Fehlende `]' if [ -n $1]; then echo "parameterized"; fi
24885
Why doesn't this command output "1"?  echo 1 | echo   I imagine it working this way:  1. echo 1 (outputs 1) 2. | echo (takes the 1 as an input, then echos it)   Isn't this what should happen?
26600
On the bash command-line, ↑ gives me the previous command. On the command-lines in ipython or matlab, when I type a few characters, ↑ gives me the previously entered command starting with those characters. How can I enable exactly this behaviour in bash? I am aware of more advanced ways of searching through the command-line history, but sometimes a simple way is more convenient.
111425
Often, I read something like command time(1) or printf(3) in the manpages.  What do the numbers in the brackets stand for?