What do the following two things give you?
- ls -l {,/usr}/bin/*{cat,grep}
- No usage of ./script.sh $something
When I first saw those *cat and *grep symbolic links, I had a fascinating feeling. If you are a Gentoo user, then you must have typed this command during the installation:
$ cd /etc/init.d $ ln -s net.lo net.eth0
This is how you create a network interface. And I think you already can tell how this is going.
I have a script and it needs an ID in order to get data from Internet, but I don’t want to hard-coded a variable in that script or to type in prompt as parameter, and that’s no way I was going to wrap that script with an ID hard-coded in wrapping script.
So, my brain somehow got the idea from those very common symbolic links. This is a simplified case:
$ ln -s script.sh ID1 $ ln -s script.sh ID2.sh $ ./ID1 $ ./ID2.sh
The script would look like:
#!/bin/bash ID=$(basename -s '.sh' -- "$0") LINK="http://example.com/endpoint/$ID" if [[ "$1" =~ l|link ]]; then echo "$LINK" exit 0 fi echo "do something with $LINK"
I could put .sh in the end, in fact, my script actually can deal with description plus prefix like Some notes.PREFIX.ID.sh. You can even employ some kind of parameter encoding like in URL, but since I only need an ID and it’s ASCII-safe, I just directly put it in filename without encoding anything.
A bonus: I quite like how q utilizes:
$ equery f -f sym portage-utils * Searching for portage-utils ... * Contents of app-portage/portage-utils-0.30: /usr/bin/qatom -> q /usr/bin/qcache -> q /usr/bin/qcheck -> q /usr/bin/qdepends -> q /usr/bin/qfile -> q /usr/bin/qgrep -> q /usr/bin/qlist -> q /usr/bin/qlop -> q /usr/bin/qmerge -> q /usr/bin/qpkg -> q /usr/bin/qsearch -> q /usr/bin/qsize -> q /usr/bin/qtbz2 -> q /usr/bin/quse -> q /usr/bin/qxpak -> q
Those are symbolic links to q, you can actually type qsearch <pattern> or q search <pattern>.
Have you ever seen any other usage?
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.