Linked Questions

6
votes
3answers
4k views

Bash: Scope of variables in a for loop using tee

Consider: numbers="1 111 5 23 56 211 63" max=0 for num in ${numbers[@]}; do [ $num -gt $max ]\ && echo "old -> new max = $max -> $num"\ && max=$num ...
5
votes
3answers
8k views

Using time on bash functions (not commands)

How can one measure individual calls to bash functions from inside the bash file. I have a program that I call using the command eclipse -b col_solve.pl -e "myPred" This call outputs some ...
3
votes
3answers
8k views

Piping in awk scripts

I'm trying to write a ls wrapper that uses awk to parse the output of ls -lhF. Right now I've split the program into two files - my_ls.sh and my_ls.awk. my_ls.sh's only purpose is to pipe the output ...
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. ...
4
votes
2answers
4k views

Pass a command to ROOT from a shell script and having it stay open

I am writing a bash script to perform some analysis using the program ROOT. I want to run some initial command to load the result of the analysis, then continue using ROOT interactively. The analysis ...
3
votes
3answers
2k views

Please help explain this bash output redirection

This script was posted as answer to a Question. And I'm trying to work out what's going on. result=$( { { ssh host app-status >&3 3>&-; echo "$?" } | { until read -...
3
votes
2answers
604 views

are there generally available programs that use file descriptors more than 2?

Standard file descriptors <=2 are opened by default. A program can write to or read from, a file descriptor more than 2, without using the open system call to obtain such a descriptor. The ...
3
votes
3answers
589 views

Print a message from the left-hand side of a pipe

I want to use a variable from the main shell in a sub shell. I did: export mysql_root_password="test" ( echo $mysql_root_password ) | dialog --gauge "Working hard..." 6 50 There is no output. Of ...
3
votes
1answer
3k views

Write data to both a file and a serial port — can I use tee?

I am trying to take the input from a serial port and write it to a file and also then read the file and send it back out the serial port to the host computer. A coworker suggested using the "tee" ...
3
votes
2answers
855 views

bash: loop through two string variables to create symbolic links

I have managed to create two bash variables, both of which are lines of strings. $oldfilenames which looks like path/old-filename-1.txt path/old-filename-2.txt path/old-filename-3.txt path/old-...
3
votes
1answer
1k views

Is it safe to use fd 3?

There are several questions that use it to do things like multiple output pipes without using process substitution: Is there a way to pipe the output of one program into two other programs? Swapping ...
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 -...
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: ...
3
votes
2answers
174 views

Is there any way I can fit this into my ~/.bashrc as a function?

I just discovered this useful bit of code on this useful-looking website. #!/bin/sh exec tclsh "$0" ${1+"$@"} proc main {} { set lines [lrange [split [read stdin] \n] 0 end-1] set count [...
2
votes
1answer
555 views

Propose additional file descriptor “stdmeta” [closed]

I know that one can define additional file descriptors for ad-hoc use. However, I see real use for a "stdmeta" file descriptor that would be supported by common CLI tools. This file descriptor would ...

15 30 50 per page