I need to do this as an alias - if possible
alias d='pushd +$1'
This won't work for some reason, because when I execute the alias it gives me this:
d 3
-bash: pushd: +: invalid number
pushd: usage: pushd [-n] [+N | -N | dir]
but this will work
~ $alias d='pushd +3'
~ $d
/Library/Java/JavaVirtualMachines $
There is something about having the plus symbol next to the argument variable that isn't working and I don't know why.
Is there a way to make this work?
Thank you,
Mike
Edit: This is for the discussion happening below:
~ $alias d='cd $1'
~ $d ~/Downloads
~/Downloads $d ~/Music
~/Music $d ~/Documents
~/Documents $
To be clear here, my problem has nothing to do with needing to know how to create an alias that accepts argument parameters.
My SPECIFIC problem is when I take the passed argument then try to include it as an argument in another command when that argument has a plus symbol next to the passed arguments variable, which starts with a dollar sign. The answer provided does not work and gives me the same error.
Edit: Based on the first answer given, the solution was to create a FUNCTION within my .bash_profile file, which I did and it worked perfectly!
This is what I added to the profile file:
d() {
pushd "+$1";
}
And though I don't believe what I am about to say will matter a hill of beans, I will say it anyways:
It is frustrating when people close questions because they assume a certain level of knowledge about the poster. This question was closed with a reference given to a post that teaches people how to write an alias that accepts an argument.
FIRST of all, that was NEVER my question, and SECOND, the proposed answer given in the closing of this question would not have gotten me any closer to a solution.
What I learned from this question and the discussion was that a function within a bash profile script will behave just like an alias. And THAT is the knowledge I needed to solve my problem.
Questions are closed far too easily on this site and in my opinion, arrogantly and without any regard for the actual or probable needs of the OP ... they get closed without any inquiry to the OP in order to determine whether or not the question should remain open ... this is a HUGE failing for this site ... making it too easy for people to dismiss the entire reason why people like us come here in the first place.