4

I would like to bind my empty line in my bash to a specific command (for example pwd, ls, ...), like so :

$<enter>
$/home/

I tried

// ~/.bashrc
alias ="pwd"

But obviously this was rejected :

-bash: alias: =pwd: not found

Any idea ?

4
  • you omit the variable name after alias the command mus be like alias var_name="pwd"
    – kasravnd
    Sep 13 '14 at 10:11
  • the purpose of this question is matching an empty line in the bash, so no variable name must be provided i think ...
    – nobe4
    Sep 13 '14 at 10:14
  • Its impossible !
    – kasravnd
    Sep 13 '14 at 10:39
  • 1
    It's not possible, because an empty line isn't a concrete thing that bash recognizes; it's simply more whitespace between two commands that is ignored.
    – chepner
    Sep 13 '14 at 18:39
3

An alternative:

PROMPT_COMMAND='_L="$(history 1)"; [ "$_L" != "$_X" ] || echo $PWD && _X="$_L"'
3
  • Great ! Can you explain how it works ?
    – nobe4
    Sep 13 '14 at 11:00
  • 1
    The bash environment variable PROMPT_COMMAND contains a regular bash command that is executed just before the command prompt is displayed. so this isn't a proper answer for this question ! because question is abut alias without name
    – kasravnd
    Sep 13 '14 at 11:05
  • 1
    yeah but as it might not be possible it's a great solution too
    – nobe4
    Sep 13 '14 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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