SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[I recognise this is a bash question, but I'd like to limit it to Slack users, forgive if it trangresses etiquette]
My .bashrc file is full of aliases and I carry it around on my USB, it's become pretty much indispensible to me.
In effort to make even more use of them, I was wondering if I could use the arguments that come after the alias-command within the alias as defined in the .bashrc.
I mean, take tar. You want to tar up a current directory tree quickly, but you want to be able to specify the name of the tar file each time (i.e. by putting it as an argument to the alias). Is it possible to have the alias recognise the argument that comes after it and so use it as the tar file name?
What I do now, is write an alias which uses a generic name for the tarfile and then I rename it after using the alias. Of course, this is straightforward in a small script, but an alias? Actually,
alias tart='tar file.tar * && mv file.tar'
does appear to work. Though it complains "tar: file.tar: file is the archive; not dumped"
I suppose that I expect that aliases are really just expansions, and that this is not possible. I expect you need to include a function (maybe) in the .bashrc.
Another way could be write out the name of the tarfile you want to use on the prompt line and press return. THis would sotr eit in the !$ expansion. Then the alias might recognise the !$ expansion. However, that's unelegant. [ehem, just tried it, alias won't expand the !$. Now, that's a sign of their being pretty elementary tools.]
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054
Rep:
thats quite correct.
If you want even more functionality try making it a function
then something like this would work
tart()
{
tar $1 *
mv $1
echo "DONE"
return 0
}
You get the gist? the main thing you wanted was I guess the fact that $1 represents the arg
I couldn't quite understand what you wanted to do there so I guess my function will be wrong.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.