0

Differently from bash shell (for create new alias):

alias test="echo test"

if I do the same thing using a bash script, alias does not run:

#!/bin/bash
alias test="echo test"

also export it, same problem:

alias test="echo test" ; export test

maybe correct: really "test" in not a variable. So, how put any aliases to bash script and let them available in my environment?

2 Answers 2

1

This question has already been answered here.

helloworld.bash

#!/bin/bash
alias helloworld="echo helloworld"

Executing the script as follows:

[vagrant@localhost ~]$ . helloworld.bash

and [vagrant@localhost ~]$ helloworld results in:

[vagrant@localhost ~]$ helloworld
helloworld
1

alias is not available in a non interactive shell. Use bash's option -i. If the -i option is present, the shell is interactive.

#!/bin/bash -i
alias test="echo test"
test

Output:

test
2
  • -bash: test: command not found
    – 030
    Nov 9, 2014 at 19:54
  • @utrecht: You're doing something wrong. test is a shell builtin.
    – Cyrus
    Nov 9, 2014 at 21:04

You must log in to answer this question.

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