# Why does not my Bash manuscript identify pen names?

In my ~/.bashrc documents stay 2 interpretations:

1. commandA, which is an alias to a longer course
2. commandB, which is an alias to a Bash manuscript

I intend to refine the very same documents with these 2 commands, so I created the adhering to Bash manuscript:

#!/bin/bash

for file in "[email protected]"
do
commandA $file commandB$file
done


Also after logging out of my session and also logging back in, Bash motivates me with command not found mistakes for both commands when I run this manuscript.

What am I doing incorrect?

0
2019-05-04 04:13:36
Source Share

If you check into the bash manpage you locate :

Aliases are not increased when the covering is not interactive, unless the expand_aliases shell alternative is set making use of shopt (see the summary of shopt under SHELL BUILTIN COMMANDS listed below ).

So place a

shopt -s expand_aliases


See to it to resource your pen names documents after establishing this in your manuscript.

shopt -s expand_aliases
source ~/.bash_aliases

0
2019-05-07 21:11:42
Source

Aliases can not be exported so they're not readily available in covering manuscripts in which they aren't specified. To put it simply, if you specify them in ~/.bashrc they're not readily available to your_script.sh (unless you resource ~/.bashrc in the manuscript, which I would not advise yet there are means to do this effectively ).

Nonetheless, features can be exported and also would certainly be readily available to shell manuscripts that are ranged from a setting in which they are specified. This can be done by positioning this in your bashrc :

foo()
{
echo "Hello World!"
}
export -f foo


As the Bash guidebook claims, "For virtually every objective, covering features are favored over pen names."

0
2019-05-07 20:49:36
Source

First of all, as ddeimeke claimed, pen names by default are not increased in non-interactive coverings.

Second, .bashrc is not read by non-interactive coverings unless you set the BASH_ENV setting variable.

Yet most notably : do not do that! Please? Eventually you will certainly relocate that manuscript someplace where the essential pen names are not set and also it will certainly damage once more.

Rather set and also make use of setting variables as faster ways in your manuscript :

#!/bin/bash

CMDA=/path/to/gizmo
CMDB=/path/to/huzzah.sh

for file in "[email protected]"
do
$CMDA "$file"
$CMDB "$file"
done

0
2019-05-07 19:54:56
Source