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:
usage: mem memcache-command [arguments]
where memcache-command might be:
set
add
get[s]
append
prepend
replace
delete
incr
decr
cas
stats
verbosity
version
notes:
exptime argument is set to 0 (no expire)
flags argument is set to 1 (arbitrary)
There are 4 alternatives - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.
Alas, I don't know much about memcache, but there's a couple of things I can improve.
If you give printf one format specifier, e.g. %s, but several arguments, it will reuse the format:
printf "%s " a b cdisplays "a b c"
Next, there's a shell abbreviation, in bash at least, for all the parameters: $@
Quote it to keep any whitespace:
printf "%s " "$@"Later in the command you use a local variable $a, but you don't alter it, so you may as well use the original $3 (I think).
This shortens your command from 235 to 193 bytes.
mem(){ { case $1 in st*|[gid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf "\r\nquit\r\n";}|nc -n 127.0.0.1 11211; }Now, if you give us some sample data for the dd/sed part of the command, we'll see if we can simplify that.
thx flatcap. you're right. i've made your suggested changes, and added another of my own.
when i look at this my mind says the original arg3 should be "reset(lost)" when passing through a pipe. habitually, i use local vars to prevent this as i'm typing one-liners that use a pipe. but you're right, it's not necessary here.
also the last printf isn't necessary if you're using gnu sed.