unset bar
to make 'bar' function annihilated.
For permanent usage you can put this (bar) function in your .bashrc (for bash) or in .profile (for sh).
With:
. ~/.bashrc
you can get all new inserted functions in .bashrc (so the function 'bar'
or whatever name you choose) immediately available.
$ bar cat backup.sh? <y/n> ^C
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:
/bin/ls
. You sort by time (ls -t), then reverse the list (-r) and extract the last entry. It'd be more efficient to use head on the non-reversed list. (Head would read one line and stop, rather than tail reading all the lines)./bin/ls -t | head -1
. You read the response from the user, but don't quote it in the test. If the user types "no thanks", bar() fails.[[ "$a" != "n" ]]
. Also you don't need bash's extended test syntax [[ ... ]], unless you want to search for a regex, e.g.[[ ! "$a" ~ ^n ]]
matches "n", "no", "non", "nein" ... . Finally, I don't understand why you've used eval. You don't need it and it prevents quoting the filename. Good:cat "$foo"
Fu:cat -- "$foo"
. My version:bar() { F=$(/bin/ls -t|head -1) && read -ep "cat $F? <y/n> " A && [ ! "$A" = "n" ] && cat -- "$F";}