commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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:
Sometimes you have a script that needs and inputfile for execution. If you don't want to create one because it may contain only one line you can use the `
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.
If you can do better, submit your command here.
You must be signed in to comment.
I really would like to know why someone votes -1 for this ?
I have found that since this board is used by people with different skill levels, some may encounter difficulty with a certain command and quickly vote it down. Though I found your command to work, I also have to say that there is a huge speed penalty associated with it. Perhaps not the best application, but as a way to show our fellow commandlinefu readers and contributors that your command works, here is my example:
time wc -l <
10675
real 0m0.497s
user 0m0.001s
sys 0m0.027s
time wc -l /etc/services
10676 /etc/services
real 0m0.006s
user 0m0.003s
sys 0m0.000s
Let me try to post the two commands again:
'time wc -l <
'time wc -l /etc/services'
Hope it works this time.
# time wc -l <
# time wc -l /etc/services
yes I have to agree that there is a huge speed penatly when useing this command. But I also have to say that for bash scripts that use mysql this is the best method that worked for me without using the mysql shell.
One could call it 'quick and dirty' but if you use it for bash scripts that are called every x hours, the speed penalty can be neglected I think.
Hum... Why dont simply use stdin ? oO
echo "SELECT COUNT(*) FROM mysql.user" | mysqlCOUNT(*)
9
For bash you should use
mysql <<< "SELECT COUNT(*) FROM mysql.user"works on zsh as well
let's try again:
<(some command)works on zsh as well
Isn't this exactly the same as using a pipe? The
some command | any_script.shThe 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.
For some reason a lot of what I just posted disappeared...
Isn't this exactly the same as using a pipe? The
<(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.shThe 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.
all of you are right, BUT you can do things with this syntax you can not do with pipes.
./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.
By using this syntax you /are/ using named pipes. Read the "process substitution" section of the bash manual.
You're right that you can't do the command in your last comment using normal pipes -- I am not disputing that.
But my objection is in regard to the original command you posted. Let me explain again. The command you posted:
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 like
any_script.sh < /dev/fd4where /dev/fd4 is the fifo connected to the output of
some commandSo /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, like
some command | any_script.shThe process substitution is only needed when you want the fifos which are set up to be passed as arguments to a command.