Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I was using openSUSE 11.3, it came with several aliases already set up. Two that I used a lot were + for pushd . and - for popd. Now on Debian, I can't figure out how to create the second one. alias -=popd tries to read -= as a command option to alias. I've tried putting quotes (both single and double) around it, and preceding it with a backslash, but I just keep getting error messages. Any suggestions?

Thanks

share|improve this question

2 Answers 2

up vote 10 down vote accepted

try this:

alias -- -=popd

worked at least for me:

usr@srv % alias -- -=echo
usr@srv % - test
test
share|improve this answer
    
Thanks, works perfectly. What does the -- do, exactly? –  Wolf Apr 24 '11 at 16:22
3  
@Wolf: For most commands, -- marks the end of options; everything after it is arguments. For example, logger foo -x bar would log "foo bar" and treat -x as an option, while logger -- foo -x bar would treat it as an ordinary word in the message "foo -x bar". –  grawity Apr 24 '11 at 16:58
1  
The -- indicates that no more options follow on the command line, following -'s aren't interpreted as options. So this allows you to cat files that start with a - ;-) –  binfalse Apr 24 '11 at 17:07
    
@grawity and @binfalse: Thanks for the explanation, that's very helpful! Very good to know. –  Wolf Apr 24 '11 at 17:09

In bash you can create functions named as such:

+() { pushd "$@"; }
-() { popd "$@"; }
share|improve this answer
    
what is $@? –  Lazer Apr 24 '11 at 16:54
2  
@Lazer: In sh and bash, $@ expands to all arguments given to the function or script. Unquoted it works the same way as $*. When inside double quotes, however, it expands to exactly the same words as originally given, without any additional splitting. –  grawity Apr 24 '11 at 17:05
    
@Lazer: $@ expands to all the parameters passed to the function (equivalent to "$1" "$2" ...). For more information, do man bash and search for Special Parameters. –  André Paramés Apr 24 '11 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.