Setting up alias in bash
Ok so in csh I have the following alias's and what they do
Code:
alias cl 'cd \!* && ls -alh' goes to /proj/P09/rev45/workarea/<user>/. The g command is because I am constantly switching between projects and revisions. Sometimes I need to use bash so I have tried setting up alias's in my .bashrc file exactly the same but as you know the \!* doesn't work. So far I have the following Code:
alias cl="xargs -I {} bash -c 'cd {} && ls -alh' <<<" Any thoughts on how to write a file in bash to perform the same as in csh? What I read bash says "bash has no mechanism for using argument in the replacement text, as in csh. If arguments are needed, a shell function should be used." I didn't really want to use a function though, I know someone out there can help me out, it is really close to being correct I think. Someone smart help me out here. |
Sorry for the double post still new to linux and this forum don't know how to delete message
|
I'm not sure you could do it with an alias, but you could do it with a shell function :)
Just add to your .bashrc: Code:
g(){ |
Ok great I am really new to everything in Linux. I was trying to use an alias because it is really easy to do in csh. That function looks simple, and works great.
Now I am struggling with the second part, for csh first I have Code:
alias g 'cl /home/\!:1/ Code:
cl(){ bash: /home/iwambeke/.bashrc: line 32: syntax error near unexpected token `then' bash: /home/iwambeke/.bashrc: line 32: ` if["$2"="??"] || ["$2"="?"];then' |
1. please use code tags when posting https://www.linuxquestions.org/quest...do=bbcode#code
2. Code:
g() http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ PS Add Code:
set -xv |
First, please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, bolding, colors, or other fancy formatting.
Second, this... Code:
alias cl="xargs -I {} bash -c 'cd {} && ls -alh' <<<" Also, remember that an alias is just a text substitution feature, not a command. If the first token (word) on the line matches a preset alias, the text of the alias is inserted at that point. Everything after the first token stays where it is. So there's no way to position arbitrary arguments that way. That's what makes shell functions so much more flexible. They're basically scripts that execute inside the current environment. As for your second one, first, understand that "[" is a command (an synonym for test), and everything after it is an argument to that command, so they need to be whitespace separated. Also, test doesn't have pattern-matching ability. As long as you're using bash, you should use the new "[[" keyword instead, which is broadly compatible, but more flexible, and does support pattern matching. Speaking of which, I'm not really sure what you are doing here: Code:
[ "$2" = "??" ] For pattern matching two characters (of any kind) in bash, you'd use this: Code:
[[ $2 == ?? ]] Code:
if [[ $2 ]]; then See the following links for more on bash tests. When using bash or ksh, it's recommended to use [[..]] for string/file tests, and ((..)) for numerical tests. Avoid using the old [..] test unless you specifically need POSIX-style portability. http://mywiki.wooledge.org/ArithmeticExpression http://mywiki.wooledge.org/BashFAQ/031 http://wiki.bash-hackers.org/commands/classictest http://wiki.bash-hackers.org/syntax/...nal_expression http://wiki.bash-hackers.org/syntax/arith_expr |
All times are GMT -5. The time now is 08:39 AM. |