Tag Info

Hot answers tagged

21

The <<< starts a “here string”: The string is expanded and fed to the program’s stdin. (In your case, there is not much of expansion happening.) It is equivalent to this: echo ddd | md5sum On the other hand, << starts a here document. All the following lines up to one containing the marker ddd will comprise the input of the program. (You ...


12

<<< introduces a here string: the string after <<< is passed as input to the command. This originates from rc (a Plan 9 shell), and is also present in zsh, ksh93 and bash. << introduces a here document: subsequent lines of the shell script are passed as input to the command, and the string after << is a terminator. Here ...


8

The second example: find . -name *.txt -print0 | xargs -0 cat > out.txt Is completely legal and will recreate the file, out.txt each time it's run, while the first will concatenate to out.txt if it runs. But both commands are doing essentially the same thing. What's confusing the issue is the xargs -0 cat. People think that the redirect to out.txt is ...


7

In many shells including ksh, zsh and bash, time is a keyword and is used to time pipelines. time foo | bar Will time both the foo and bar commands (zsh will show you the breakdown). It reports it on the shell's stderr. time foo.sh > bar.txt Will tell you the time needed to open bar.txt and run foo.sh. If you want to redirect time's output, you ...


4

When you're running it in the shell, you're actually using the bash built-in function, which looks like this: anthony@Zia:~$ time perl -e 'sleep 1' real 0m1.003s user 0m0.000s sys 0m0.004s Cron isn't using the bash built-in; it's using /usr/bin/time: anthony@Zia:~$ /usr/bin/time perl -e 'sleep 1' 0.00user 0.00system 0:01.00elapsed 0%CPU ...


4

What is the purpose of having these two operators then? That's an easy one: Because there are different use cases. Sometimes it is useful to truncate the target file to size 0 first, sometimes (e.g. log files) it makes more sense to append data to a file. In this case it makes no sense to append. You want a file with exactly the content of the files ...


4

Lots of programs send output to stderr that isn't actually indicative of errors. For example, in some programs it is used to display information that would otherwise affect the output of the program (which is designed to be piped into another program). You can, however, do this: exec 2>/dev/null I wouldn't recommend doing this outside of a script.


3

( mysqldump --opt --databases $dbname1 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1; \ mysqldump --opt --databases $dbname2 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1; \ mysqldump --opt --databases $dbname3 --host=$dbhost2 --user=$dbuser2 --password=$dbpass2; \ mysqldump --opt --databases $dbname4 --host=$dbhost2 --user=$dbuser2 ...


3

If I understand correctly, you want to detect when a.out is reading data from standard input, and when it does send it that data and also write that data to the same log file stdout is redirected to to simulate the local echo to the terminal when run interactively? Then maybe a solution (bash syntax) would be something like: mkfifo strace.fifo { while ...


3

It happens that the command you're running under nohup never writes to stdout or stderr, and that you aren't sending any input to it. But nohup has no way to know that, so it tells you that any input would be discarded and any output would be written to nohup.out. To avoid this, redirect nohup's stdin, stdout and stderr to /dev/null. ssh -t esolve@hostname ...


3

Not all versions of time support the -o and --output arguments. You will want to run the command like this: (time script.sh) 1> /dev/null 2> /tmp/logFile This will put the output of script.sh into /dev/null and the results to /tmp/logFile. If you want both STDERR and STDOUT to go to the log file you can run it like this: (time script.sh) ...


2

/usr/bin/time outputs to stderr, so you will need to redirect that. /usr/bin/time foo.sh 2>bar.txt If you use bash' time builtin, you need to write it differently: (time ls) 2>bar.txt Alternatively, GNU time supports an --output argument: /usr/bin/time --output bar.txt foo.sh


2

I don't think what you want is possible. See this superuser thread titled: How do I detach a process from Terminal, entirely?. I think you have essentially 3 options. Option #1 Run the scripts that are polluting you terminal such that they're run like so: nohup somescript &> /dev/null & Which should run their STDOUT & STDIN to ...


2

If you are on Linux, and I read your question correctly, yes look in /proc. For a specific process look in /proc/[pid]/fd, e.g. ls -l /proc/123/fd/ There is also a special way to reach current process fd's by: /proc/self/fd. Note that e.g. ls -l /proc/self/fd would be for the ls process and not for your current shell, which you can see by: cat ...


2

(This refers to bash in case of doubt) The output of one command or one pipeline can be made the input of another command by creating a (or extending the existing) pipeline: command1 | command2 command1 | command2 | command3 Several commands (including pipelines) can be combined with a subshell or a list (group command). This combination becomes the ...


2

In your comment to @tink's answer you want seperate files in the .gz files: mysqldump --opt --databases $dbname1 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1 > '/var/tmp/$dbhost1.$dbname1.sql' ; mysqldump --opt --databases $dbname2 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1 > '/var/tmp/$dbhost1.$dbname2.sql' ; mysqldump --opt ...


1

I would go with the second one. The redirect of stdout gets caught by bash when you hit enter, so it's not like you create a new redirect for every line of find/xargs (which might have been their thinking). If out.txt doesn't exist they should be identical, if it already has data, then the second one at least resets the file to known content (that is, no ...



Only top voted, non community-wiki answers of a minimum length are eligible