Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating an alias for the following command with the tree program:

tree -P '*name*'

This works exactly as I want. But when I create an alias for this command, the command behaves differently: It only prints directories and not files.

In .bash_aliases

function tree_seek {
tree -P '*$1*' 
}

alias treeseek='tree_seek'

Why does the alias treeseek name does not do the same as tree -P '*name*'.

share|improve this question
2  
@artistoex Could you elaborate on that? From what I can tell, this is no different from the deleted answer you commented on, since double-quoted asterisks aren't subject to expansion, so tree -P "*$1*" should work as well. – Daniel Beck Feb 14 '13 at 10:53
    
Indeed, using double quotes like Daniel Beck said works as well. Could you post this as a seperate answer? – Bentley4 Feb 14 '13 at 10:56
    
Aliases don't handle arguments, use a shell function. – vonbrand Feb 15 '13 at 3:27
up vote 2 down vote accepted

In Bash, single quotes won't interpolate anything. Try using double quotes in your function instead:

function tree_seek() {
  tree -P "*$1*" 
}

alias treeseek='tree_seek'
share|improve this answer
    
@daniel-beck: Sorry, I certainly didn't mean to hijack your answer. I didn't see your comment before I posted my answer. – Eero Helenius Feb 14 '13 at 10:58
    
+1 for finding out and for your apologies to Daniel Beck. – jaume Feb 14 '13 at 11:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .