mysql -uuser -ppass dbname < <(echo "SELECT * FROM database;")
This can be very usefull when working with mysql as I showed in the example code above. This will create a temporary file that is used to execute mysql and for example select all entrys from a specific database.
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
echo "SELECT COUNT(*) FROM mysql.user" | mysql
COUNT(*) 9mysql <<< "SELECT COUNT(*) FROM mysql.user"
<(some command)
works on zsh as wellsome command | any_script.sh
The process substitution is useful when you want to put some command's output into any_script.sh but any_script.sh won't take standard input for that particular function, only a filename. I've come across this a few times, I think with mplayer in one case. There's the similar >(some command) too, which provides a fifo to any_script.sh by filename and any_script.sh can thereby write to the input of some command.<(some command)
runs some command and connects its output to a fifo whose path is substituted into the command line, looking to any_script.sh as a filename. But then you're using the < to redirect the contents of the file (the fifo) to the standard input of any_script.sh. This is exactly the same as using a pipe like this:some command | any_script.sh
The process substitution is useful when you want to put some command's output into any_script.sh but any_script.sh won't take standard input for that particular function, only a filename. I've come across this a few times, I think with mplayer in one case. There's the similar >(some command) too, which provides a fifo to any_script.sh by filename and any_script.sh can thereby write to the input of some command../script.sh -c <(echo -e "du -cs %d > /tmp/dusize\nls -al %d") -u <(echo -e "cb0\nadmin\nroot") -h "/home/%U"
This sample script does need a command file, a userfile and a directory with placeholer. command file describes commands to excute one after another. userfile contains usernames on a line. Now the script reads in all those things and executes all commands in the command file in all diretorys whith all %U being replaced by usernames and alls %d being replaces by a diretory. Now you see this script takes 2 files as argument which are created in background. I thinks you can't do such things with pipes. Maybe with named pipes but I don't know much about them.any_script.sh < <(some command)
The<(some command)
gets substituted with the path to the fifo which is set up so you're left with something likeany_script.sh < /dev/fd4
where /dev/fd4 is the fifo connected to the output ofsome command
So /dev/fd4 is being redirected as *standard input* to any_script.sh -- its path is not being passed as an argument. You can do this with a normal pipe, likesome command | any_script.sh
The process substitution is only needed when you want the fifos which are set up to be passed as arguments to a command.