Find the answer to your Linux question:
Results 1 to 5 of 5
how to check if a string is already used as an alias in bash?...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41

    [SOLVED] how to check if a string is already used as an alias?

    how to check if a string is already used as an alias in bash?

  2. #2
    Linux Engineer b2bwild's Avatar
    Join Date
    Jul 2008
    Location
    Behind You!
    Posts
    1,108
    try this

    # alias | grep yourstring
    Never make any misteaks.

    Read my Blog at --> Penguin Inside Subscribe Feed

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41
    Quote Originally Posted by b2bwild View Post
    try this

    # alias | grep yourstring
    Thank you, but I needed this in .bashrc: I want to unalias that string if it already is an alias of something
    Code:
    if str is alias
      unalias str
    Sorry for not writing this immediately

  4. #4
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    This should be what you are looking for
    Code:
    if `alias|grep -q str`; then unalias str; fi
    You can also re-write the above if block in this format:
    Code:
    [ -n "`alias|grep str`" ] && unalias str

  5. #5
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41
    Quote Originally Posted by secondmouse View Post
    This should be what you are looking for
    Code:
    if `alias|grep -q str`; then unalias str; fi
    You can also re-write the above if block in this format:
    Code:
    [ -n "`alias|grep str`" ] && unalias str
    Thank you! it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...