![]() |
make an alias to a command with an argument?
some kind user posted a way to get a process by name.
I was thinking wouldn't it be great to have a "getpid" command. So, having no idea really what i was doing, I tried to create the following file in Pico: ----- #!/bin/sh ps -auxxw | grep $ ---- I tacked on the $ cause i figured that might be a way to pass an argument. (laugh away). then i saved it out, and did a "chmod 755 getpid" and then typed rehash. then i tried: %getpid itunes and got a whole pid listing. not what i wanted. how would i pass an argument to that script or whatever the heck it is I just made. ;-) --loren |
Code:
for tcsh shell, define an alias: |
so how long does the alias persist and...
Great! thanks. but how long does that alias persist (from reboot to reboot or is it temporary?). If it persists, where is it stored. (I used the tsch one)
also, i have no idea at all how i could recreate that with a different syntax with an argument. if i type alias command_name 'some command string' then where does the argument go, in general terms? TIA |
the tcsh shell maintains a list of aliases which can be manipulated with the alias and unalias commands.
they are persistent for that shell's existence. to get aliases defined automatically at shell startup, define them in the file ~/.tcshrc. or you can read the file at /usr/share/init/tcsh/README and implement the suggested scriptage there, but some find that overly rococo. check the man pages for tcsh to find the docs on aliases; you'll have to search for the alias command: % man tcsh arguments in aliases follow the form of the command your referencing, e.g.: Code:
alias zloc "locate \* | perl -ne 'print if m#\!*#i'" you've got some homework to do. read up on aliases in the tcsh man pages, and look for examples on the web and in some books. |
I've also had luck w/ defining alias commands in my "~/.login"
cd ~ pico .login alias bye logout alias ftplog cat /var/log/ftp.log alias jawho 'last | grep still' alias cuthere 'echo "-------------- Cut Here -------------- " > /dev/console' etc... |
I use my ~/.cshrc file (in tcsh) and the form
Code:
alias srchfrlmn "cat \!:1 | grep lmn"To use it, I would say something like srchfrlmn alphabet.txt, and the command would look through alphabet.txt and print out instances of lmn. Therefore, the code you're looking for to pass a variable is \!:1, at least in tcsh aliases. |
thanks
thanks, yall. that's what i was looking for. especially:
> the code you're looking for to pass a variable is \!:1 you're right i have some homework to do, but reading through man pages to learn more about the ins and outs of unix shells is not it! I'm trying to have my computer make the other elements of my life easier, but its taking over! help! lol (anyway, that's why i'm thankful for a forum like this--people like yall sharing some knowledge ;-) |
tail system log
Hey mT,
I was intrigued by your last alias listed in your post from above but got: tail: illegal option -- v ... when I tried it. Please toss me a hint! TIA and regards |
hey thatch, whoops, i run fink here...
Code:
$ wiz tail |
Thanks mT. I should have known but I haven't seen tail in any of the fink packages. Which one is it in so I can grab it? TIA!
I like the idea of a homegrown command locator. I did the whereisit alias tip from the recent hint on that and it seems to work great. Regards, thatch |
tail
Unless I'm missing something in the exchange, the tail command isn't a fink thing. It's standard c-shell stuff. (I don't know about other shells as I've only used c-shells and their derivatives like tcsh.)
Same with head. tail -n xxx.txt give you the last n lines of a text file xxx.txt head -n xxx.txt gives you the first n lines of the file xxx.txt I use them all the time and don't have fink installed. |
Yes, tail comes with the standard OS X install, however fink gives you an updated version, with, for instance, the -v option.
Code:
[11:39][brandg /Users/brandg] %echo abc > abc.txt |
Yes, but what's the name...
xchanyazy,
Do you know what the name of the package that contains the head and tail commands in fink is? If so, could you please tell me what it is so I can install it? TIA |
I'm pretty sure it's textutils.
|
Yup!
Thanks xchanyazy. That was it! :)
Regards, thatch |
Quote:
Below is just background. You don't have to read it unless you want to know the purpose of the script. ----------------------- While at work, I like to contact my home computer, which has a dynamic ip. So, I have scripts set up on my home computer to get its wan address from the router (without www.whatismyip.com or other such things) and then upload it to my ftp account on campus. Then I have a script called homeip on my work computer which grabs that ip address from that ftp server. It is now getting old to have to check my frequently changing ip address first before I do a scp, so I wrote the following scripts to try to get around that: Code:
#!/bin/shCode:
#!/bin/shscpThing nameOfFile would start an scp, with my input only that of typing my passphrase. Because my training in shell scripting comes from reading posts at MacOSXHints.edu or searching at Google.edu, I don't know how to assign outputs of scripts to variables to be used later, except in sh. And I don't know how to pass arguments to scripts except in tcsh (which I learned from this post). That is the reason for my question. |
Quote:
http://www.tldp.org/LDP/abs/html/othertypesv.html |
Thank you very much, hayne!
Code:
#!/bin/sh |
Is it possible to do this in a single alias?
like macmath, i would like to scp from my school's server to my mac. the normal command would be scp username@address:~/$1 ~/desktop/ with $1 being a file path like st/rt/file.gzip When I try to alias it, it will not copy the $1 into the alias. Any help? |
Quote:
In bash, aliases are not as powerful - you need to use bash functions to pass parameters. E.g.: grepfind () { find . -type f -name "$2" -print0 | xargs -0 grep "$1" ; } |
| All times are GMT -5. The time now is 10:40 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.