Skip to main content
deleted 16 characters in body
Source Link
nichen
  • 275
  • 1
  • 2
  • 8

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing is

$ cat -n test.sh
    1 #!/bin/bash
    2 alias somecommand='ls -alF'
    3 alias
    4 somecommand
$ ./test.sh
alias somecommand='ls -alF'
./test.sh: line 4: somecommand: command not found

... as shown above, if I run the command "alias" in the script it turns out that bash has take my command "somecommand"taken somecommand into the aliases, but if I run the command "somecommand"somecommand itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing

$ cat -n test.sh
    1 #!/bin/bash
    2 alias somecommand='ls -alF'
    3 alias
    4 somecommand
$ ./test.sh
alias somecommand='ls -alF'
./test.sh: line 4: somecommand: command not found

... as shown above, if I run the command "alias" in the script it turns out that bash has take my command "somecommand" into the aliases, but if I run the command "somecommand" itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing is

$ cat -n test.sh
    1 #!/bin/bash
    2 alias somecommand='ls -alF'
    3 alias
    4 somecommand
$ ./test.sh
alias somecommand='ls -alF'
./test.sh: line 4: somecommand: command not found

... as shown above, if I run the command "alias" in the script it turns out that bash has taken somecommand into the aliases, but if I run the somecommand itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!

added 182 characters in body
Source Link
nichen
  • 275
  • 1
  • 2
  • 8

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing is,

screenshot from my ubuntu 16.04

$ cat -n test.sh
    1 #!/bin/bash
    2 alias somecommand='ls -alF'
    3 alias
    4 somecommand
$ ./test.sh
alias somecommand='ls -alF'
./test.sh: line 4: somecommand: command not found

... as shown above, if I run the command "alias" in the script it turns out that bash has take my command "somecommand" into the aliases, but if I run the command "somecommand" itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing is,

screenshot from my ubuntu 16.04

... as shown above, if I run the command "alias" in the script it turns out that bash has take my command "somecommand" into the aliases, but if I run the command "somecommand" itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing

$ cat -n test.sh
    1 #!/bin/bash
    2 alias somecommand='ls -alF'
    3 alias
    4 somecommand
$ ./test.sh
alias somecommand='ls -alF'
./test.sh: line 4: somecommand: command not found

... as shown above, if I run the command "alias" in the script it turns out that bash has take my command "somecommand" into the aliases, but if I run the command "somecommand" itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!

Source Link
nichen
  • 275
  • 1
  • 2
  • 8

Can't use alias in script, even if I define it just above!

I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing is,

screenshot from my ubuntu 16.04

... as shown above, if I run the command "alias" in the script it turns out that bash has take my command "somecommand" into the aliases, but if I run the command "somecommand" itself it will still not be recognized!

Everything is right if I use the command "sh" to run the script.. so is it a bug of bash? Or is there something I'm missing?

Any help is appreciated!