You are not logged in.
Pages: 1
Hi, I'm trying to set up a function in my .bashrc to automatically direct stdout and sterr to /dev/null as well as background the process. The only problem I'm having is trying to set it up so I can use it with a program and its arguments, like "gedit file.txt". So far I've tried
q() {
"$@" &> /dev/null &
}
q() {
"$*" &> /dev/null &
}
q() {
"$1 $2" &> /dev/null &
}
and without quotes. Every time it returns exit status of 127, "command not found" probably because it tries to run file.txt, it does show a blank gedit window.
I want to be able to type "q gedit file.txt" instead of having to type "gedit file.txt &> /dev/null &" every time. Thanks for the help.
Last edited by Halcyon22 (2010-11-10 10:25:43)
Offline
I seem to have fixed it with.
q() {
arg[1]=$1
arg[2]=$2
${arg[@]:1:2} &> /dev/null &
}
Offline
q() {
"$@" &>/dev/null &
}
works for me. (q gedit foo.txt)
"$@" is equivalent to "$1" "$2" ...
Edit:
BTW, in your last post, ${arg[@]:1:2} will not work if "$2" contains spaces. You should put double quotes around it. Or, you could have just written:
q() { "${@:1:2}" &>/dev/null & }
which is equiv. to
q() { "$1" "$2" &>/dev/null & }
which, of course, is less "portable" than "$@"
Last edited by lolilolicon (2010-11-10 10:45:02)
This silver ladybug at line 28...
Offline
Hmmm you're right, thanks for clearing it up.
Offline
Pages: 1