Linked Questions

3
votes
1answer
52 views

Is there a way to bypass the pipe in a shell script or function?

I would like to write a small wrapper around ps so that no matter what the options are or if I grep the result, I could have the first line of the output of ps which tells me what the columns are. ...
154
votes
6answers
158k views

How big is the pipe buffer?

As a comment in I'm confused as to why "| true" in a makefile has the same effect as "|| true" user cjm wrote: Another reason to avoid | true is that if the command produced ...
33
votes
2answers
44k views

File descriptors & shell scripting

I am having a very hard time understanding how does one use file descriptors in shell scripts. I know the basics such as exec 5 > /tmp/foo So fd 5 is attached to foo for writing. exec 6 < /...
198
votes
6answers
192k views

How create a temporary file in shell script?

While running a script, I want to create a temporary file in /tmp directory. After execution of that script, that will be cleaned by that script. How to do that in shell script?
223
votes
9answers
151k views

How can I send stdout to multiple commands?

There are some commands which filter or act on input, and then pass it along as output, I think usually to stdout - but some commands will just take the stdin and do whatever they do with it, and ...
98
votes
11answers
82k views

How to grep standard error stream (stderr)?

I am using ffmpeg to get the meta info of an audio clip. But I am unable to grep it. $ ffmpeg -i 01-Daemon.mp3 |grep -i Duration FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice ...
0
votes
4answers
315 views

How to pipe fd 3 to consumer instead of fd1 / fd2

I was hoping to do something like this: echo 'foo' >&3 3| cat Basically, I want to write 'foo' to 3, and then only pipe the data in 3 to cat. But the above doesn't work, I get: bash: 3: ...
93
votes
5answers
106k views

What's the difference between eval and exec?

eval and exec are both built in commands of bash(1) that execute commands. I also see exec has a few options but is that the only difference? What happens to their context?
4
votes
3answers
3k views

Howto run interactive commands, as another user

I'm trying to write a bash script that context switches to another user (root, in this case) executes a set of commands to i. create a user (interactively prompting invoker for username) then ii. ...
88
votes
4answers
103k views

Why is `while IFS= read` used so often, instead of `IFS=; while read..`?

It seems that normal practice would put the setting of IFS outside the while loop in order to not repeat setting it for each iteration... Is this just a habitual "monkey see, monkey do" style, as it ...
71
votes
3answers
76k views

What does “3>&1 1>&2 2>&3” do in a script?

I saw this line in a script: DEVICE=`dialog --inputbox "Festplatten-Laufzeit auslesen. Gebe Sie das gewünschte Device an: " 0 70 "" 3>&1 1>&2 2>&3` What is 3>&1 1>&...
11
votes
4answers
15k views

Bash script to detect the version control system by testing command return status

I am working on a bash script that I would like to work for several types of VCS. I am thinking of testing if a directory is a repo for a system by running a typical info command and checking the ...
7
votes
2answers
5k views

A while loop and an here-document - what happens when?

I have this while loop and here-document combo which I run in Bash 4.3.48(1) and I don't understand its logic at all. while read file; do source ~/unwe/"$file" done <<-EOF x.sh y.sh EOF ...
34
votes
3answers
21k views

How to redirect stderr and stdout to different files and also display in terminal?

I want to see the output of a command in the terminal as if there was no redirection. Also, stderr needs to be redirected to err.log and stdout needs to be redirected to stdout.log. It would be nice ...
0
votes
1answer
926 views

How to read an open file descriptor from outside the writing process

How do you open a file descriptor and echo it to a terminal while it's being written to from a process? I have a backup program, Duplicity, that writes its logs to a file descriptor specified by the -...

15 30 50 per page