How to run an alias in a shell script?
up vote
83
down vote
favorite
I have an executable file mpiexec
, whose full path is ~/petsc-3.2-p6/petsc-arch/bin/mpiexec
. Since I want to execute this command in different directories (without having to retype the entire path), I setup an alias in my home .bashrc
file:
alias petsc="~/petsc-3.2-p6/petsc-arch/bin/mpiexec"
which allows me to execute this mpiexec
file at the command prompt easily by typing:
petsc myexecutable
I tried to write a shell script file, named script
, using my new alias petsc
as a command. After giving my shell script the appropriate permissions (using chmod
), I tried to run the script. However, it gave me the following error:
./script: line 1: petsc: command not found
I know that I could just write the full path to the mpiexec
file, but it is cumbersome to write the full path everytime that I want to write a new script. Is there a way that I can use my alias petsc
inside the script file? Is there a way I can edit my .bashrc
or .bash_profile
to make this happen?
bash scripts alias
add a comment |
up vote
83
down vote
favorite
I have an executable file mpiexec
, whose full path is ~/petsc-3.2-p6/petsc-arch/bin/mpiexec
. Since I want to execute this command in different directories (without having to retype the entire path), I setup an alias in my home .bashrc
file:
alias petsc="~/petsc-3.2-p6/petsc-arch/bin/mpiexec"
which allows me to execute this mpiexec
file at the command prompt easily by typing:
petsc myexecutable
I tried to write a shell script file, named script
, using my new alias petsc
as a command. After giving my shell script the appropriate permissions (using chmod
), I tried to run the script. However, it gave me the following error:
./script: line 1: petsc: command not found
I know that I could just write the full path to the mpiexec
file, but it is cumbersome to write the full path everytime that I want to write a new script. Is there a way that I can use my alias petsc
inside the script file? Is there a way I can edit my .bashrc
or .bash_profile
to make this happen?
bash scripts alias
How about adding the alias to.bash_aliases
? Also how about aliasing the absolute path instead of relative path likealias petsc='/home/user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
– Nitin Venkatesh
Jan 26 '12 at 18:17
@nitstorm: Neither solution seems to work... I still get the same error as before
– Paul
Jan 26 '12 at 18:21
Related: unix.stackexchange.com/questions/1496/…
– AlikElzin-kilaka
Nov 27 at 4:03
add a comment |
up vote
83
down vote
favorite
up vote
83
down vote
favorite
I have an executable file mpiexec
, whose full path is ~/petsc-3.2-p6/petsc-arch/bin/mpiexec
. Since I want to execute this command in different directories (without having to retype the entire path), I setup an alias in my home .bashrc
file:
alias petsc="~/petsc-3.2-p6/petsc-arch/bin/mpiexec"
which allows me to execute this mpiexec
file at the command prompt easily by typing:
petsc myexecutable
I tried to write a shell script file, named script
, using my new alias petsc
as a command. After giving my shell script the appropriate permissions (using chmod
), I tried to run the script. However, it gave me the following error:
./script: line 1: petsc: command not found
I know that I could just write the full path to the mpiexec
file, but it is cumbersome to write the full path everytime that I want to write a new script. Is there a way that I can use my alias petsc
inside the script file? Is there a way I can edit my .bashrc
or .bash_profile
to make this happen?
bash scripts alias
I have an executable file mpiexec
, whose full path is ~/petsc-3.2-p6/petsc-arch/bin/mpiexec
. Since I want to execute this command in different directories (without having to retype the entire path), I setup an alias in my home .bashrc
file:
alias petsc="~/petsc-3.2-p6/petsc-arch/bin/mpiexec"
which allows me to execute this mpiexec
file at the command prompt easily by typing:
petsc myexecutable
I tried to write a shell script file, named script
, using my new alias petsc
as a command. After giving my shell script the appropriate permissions (using chmod
), I tried to run the script. However, it gave me the following error:
./script: line 1: petsc: command not found
I know that I could just write the full path to the mpiexec
file, but it is cumbersome to write the full path everytime that I want to write a new script. Is there a way that I can use my alias petsc
inside the script file? Is there a way I can edit my .bashrc
or .bash_profile
to make this happen?
bash scripts alias
bash scripts alias
edited Jan 26 '12 at 18:41
enzotib
62.4k6132154
62.4k6132154
asked Jan 26 '12 at 18:11
Paul
5694714
5694714
How about adding the alias to.bash_aliases
? Also how about aliasing the absolute path instead of relative path likealias petsc='/home/user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
– Nitin Venkatesh
Jan 26 '12 at 18:17
@nitstorm: Neither solution seems to work... I still get the same error as before
– Paul
Jan 26 '12 at 18:21
Related: unix.stackexchange.com/questions/1496/…
– AlikElzin-kilaka
Nov 27 at 4:03
add a comment |
How about adding the alias to.bash_aliases
? Also how about aliasing the absolute path instead of relative path likealias petsc='/home/user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
– Nitin Venkatesh
Jan 26 '12 at 18:17
@nitstorm: Neither solution seems to work... I still get the same error as before
– Paul
Jan 26 '12 at 18:21
Related: unix.stackexchange.com/questions/1496/…
– AlikElzin-kilaka
Nov 27 at 4:03
How about adding the alias to
.bash_aliases
? Also how about aliasing the absolute path instead of relative path like alias petsc='/home/user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
– Nitin Venkatesh
Jan 26 '12 at 18:17
How about adding the alias to
.bash_aliases
? Also how about aliasing the absolute path instead of relative path like alias petsc='/home/user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
– Nitin Venkatesh
Jan 26 '12 at 18:17
@nitstorm: Neither solution seems to work... I still get the same error as before
– Paul
Jan 26 '12 at 18:21
@nitstorm: Neither solution seems to work... I still get the same error as before
– Paul
Jan 26 '12 at 18:21
Related: unix.stackexchange.com/questions/1496/…
– AlikElzin-kilaka
Nov 27 at 4:03
Related: unix.stackexchange.com/questions/1496/…
– AlikElzin-kilaka
Nov 27 at 4:03
add a comment |
9 Answers
9
active
oldest
votes
up vote
60
down vote
accepted
In your shell script use the full path rather then an alias.
In your shell script, set a variable, different syntax
petsc='/home/your_user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
$petsc myexecutable
Use a function in your script. Probably better if
petsc
is complex
function petsc () {
command 1
command 2
}
petsc myexecutable
Source your aliases
shopt -s expand_aliases
source /home/your_user/.bashrc
You probably do not want to source your .bashrc
, so, IMO, one of the first 3 would be better.
11
Point 4 don't work, unless you useshopt -s expand_aliases
in the same script.
– enzotib
Jan 26 '12 at 18:29
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Sounds as if you should put the command in a more standard location, such as/usr/local/bin
– Panther
Jan 26 '12 at 18:35
1
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
1
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
|
show 1 more comment
up vote
51
down vote
Aliases are deprecated in favor of shell functions. From the bash
manual page:
For almost every purpose, aliases are superseded by shell functions.
To create a function, and export it to subshells, put the following in your ~/.bashrc
:
petsc() {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
export -f petsc
Then you can freely call your command from your scripts.
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
3
@Paul: I added"$@"
just to handle arguments.
– enzotib
Jan 26 '12 at 19:47
add a comment |
up vote
11
down vote
Shell functions and aliases are limited to the shell and do not work in executed shell scripts. Alternatives for your case:
(if you do not bother to use
mpiexec
instead ofpetsc
) Add$HOME/petsc-3.2-p6/petsc-arch/bin
to yourPATH
variable. This can be done by editing~/.profile
and appending:
PATH="$HOME/petsc-3.2-p6/petsc-arch/bin:$PATH"
Re-login to apply these changes
Create the directory
~/bin
and
make a wrapper script named
petsc
containing:
#!/bin/sh
exec ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
if the program allows for it, you can skip the shellscript and make a symlink using the command:
ln -s ~/petsc-3.2-p6/petsc-arch/bin/mpiexec ~/bin/petsc
add a comment |
up vote
7
down vote
In bash 4 you can use special variable: $BASH_ALIASES
.
For example:
$ alias foo="echo test"
$ echo ${BASH_ALIASES[foo]}
echo test
$ echo `${BASH_ALIASES[foo]}` bar
test bar
Alternatively define as variable then use command substitution or eval
.
So for example, instead of defining the alias such as:
alias foo="echo test"
define it as:
foo="echo test"
instead. Then execute it by either:
find . -type f -exec sh -c "eval $foo" ;
or:
find . -type f -exec sh -c "echo `$foo`" ;
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.
– erm3nda
Sep 16 '17 at 9:23
add a comment |
up vote
4
down vote
In
.bash_aliases
:
petsc {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
Or put the function in
.bashrc
. Usually in.bashrc
only config settings ofbash
are stored.
In Terminal:
source .bash_aliases
- Call it:
petsc arg(s)
Advantage: you do not need export -f petsc
in .bash_aliases
. Aliases are deprecated but using .bash_aliases
for functions is ok.
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
add a comment |
up vote
3
down vote
You can force bash to execute your script as an interactive shell with the -i flag. This will tell your .bashrc file to define aliases and other functions.
Example:
~ $ grep ll .bashrc
alias ll='ls -lah'
~ $ cat script.sh
#!/bin/sh
ll
~ $ bash script.sh
script.sh: line 3: ll: command not found
~ $ bash -i script.sh
..directory contents..
More info:
$ man bash
2
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)
– muru
Jan 10 '17 at 13:12
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
add a comment |
up vote
2
down vote
- Use your aliases in your shell script.
- Source your script in your current, interactive shell instead of executing it.
So if you have a file called script.sh
with your commands that include using aliases, simply type:
source script.sh
@DavidFoerster This method works fine. Sourcing a script with the.
orsource
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which.
orsource
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.
– Eliah Kagan
Jan 10 '17 at 9:44
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
add a comment |
up vote
2
down vote
ALIASES
...
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS
below).
So the real answer to this question, for those looking to use actual aliases in shell scripts instead of alternatives to them, is:
#!/bin/bash
shopt -s expand_aliases
alias foo=bar
foo whatever
As for why I'd want to do this: Due to unusual circumstances, I need to trick a Dockerfile into thinking it's a shell script.
add a comment |
up vote
1
down vote
(EDIT: removed functions since I misread calling of mpiexec.)
If the only thing you need is less typing, why don't you just put the folder in $PATH? Or make a symlink to mpiexec from some folder in $PATH? Or (my favourite) put the alias in a script that you source in the calling script?
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
1
Cannot understand why not simply use"$@"
.
– enzotib
Jan 26 '12 at 19:49
2
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f98782%2fhow-to-run-an-alias-in-a-shell-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
60
down vote
accepted
In your shell script use the full path rather then an alias.
In your shell script, set a variable, different syntax
petsc='/home/your_user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
$petsc myexecutable
Use a function in your script. Probably better if
petsc
is complex
function petsc () {
command 1
command 2
}
petsc myexecutable
Source your aliases
shopt -s expand_aliases
source /home/your_user/.bashrc
You probably do not want to source your .bashrc
, so, IMO, one of the first 3 would be better.
11
Point 4 don't work, unless you useshopt -s expand_aliases
in the same script.
– enzotib
Jan 26 '12 at 18:29
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Sounds as if you should put the command in a more standard location, such as/usr/local/bin
– Panther
Jan 26 '12 at 18:35
1
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
1
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
|
show 1 more comment
up vote
60
down vote
accepted
In your shell script use the full path rather then an alias.
In your shell script, set a variable, different syntax
petsc='/home/your_user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
$petsc myexecutable
Use a function in your script. Probably better if
petsc
is complex
function petsc () {
command 1
command 2
}
petsc myexecutable
Source your aliases
shopt -s expand_aliases
source /home/your_user/.bashrc
You probably do not want to source your .bashrc
, so, IMO, one of the first 3 would be better.
11
Point 4 don't work, unless you useshopt -s expand_aliases
in the same script.
– enzotib
Jan 26 '12 at 18:29
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Sounds as if you should put the command in a more standard location, such as/usr/local/bin
– Panther
Jan 26 '12 at 18:35
1
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
1
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
|
show 1 more comment
up vote
60
down vote
accepted
up vote
60
down vote
accepted
In your shell script use the full path rather then an alias.
In your shell script, set a variable, different syntax
petsc='/home/your_user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
$petsc myexecutable
Use a function in your script. Probably better if
petsc
is complex
function petsc () {
command 1
command 2
}
petsc myexecutable
Source your aliases
shopt -s expand_aliases
source /home/your_user/.bashrc
You probably do not want to source your .bashrc
, so, IMO, one of the first 3 would be better.
In your shell script use the full path rather then an alias.
In your shell script, set a variable, different syntax
petsc='/home/your_user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
$petsc myexecutable
Use a function in your script. Probably better if
petsc
is complex
function petsc () {
command 1
command 2
}
petsc myexecutable
Source your aliases
shopt -s expand_aliases
source /home/your_user/.bashrc
You probably do not want to source your .bashrc
, so, IMO, one of the first 3 would be better.
edited Sep 15 '17 at 23:34
answered Jan 26 '12 at 18:19
Panther
77.6k12156258
77.6k12156258
11
Point 4 don't work, unless you useshopt -s expand_aliases
in the same script.
– enzotib
Jan 26 '12 at 18:29
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Sounds as if you should put the command in a more standard location, such as/usr/local/bin
– Panther
Jan 26 '12 at 18:35
1
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
1
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
|
show 1 more comment
11
Point 4 don't work, unless you useshopt -s expand_aliases
in the same script.
– enzotib
Jan 26 '12 at 18:29
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Sounds as if you should put the command in a more standard location, such as/usr/local/bin
– Panther
Jan 26 '12 at 18:35
1
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
1
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
11
11
Point 4 don't work, unless you use
shopt -s expand_aliases
in the same script.– enzotib
Jan 26 '12 at 18:29
Point 4 don't work, unless you use
shopt -s expand_aliases
in the same script.– enzotib
Jan 26 '12 at 18:29
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Your suggestion 2) works, but I want to be able to use the same command in multiple shell scripts without having to write the first line petsc="...". Is there a way to do this?
– Paul
Jan 26 '12 at 18:31
Sounds as if you should put the command in a more standard location, such as
/usr/local/bin
– Panther
Jan 26 '12 at 18:35
Sounds as if you should put the command in a more standard location, such as
/usr/local/bin
– Panther
Jan 26 '12 at 18:35
1
1
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
@enzotib - thank you, I added that to my answer.
– Panther
Jan 26 '12 at 18:36
1
1
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
In the point 2 you do not set an alias but a variable.
– pabouk
Nov 1 '14 at 9:58
|
show 1 more comment
up vote
51
down vote
Aliases are deprecated in favor of shell functions. From the bash
manual page:
For almost every purpose, aliases are superseded by shell functions.
To create a function, and export it to subshells, put the following in your ~/.bashrc
:
petsc() {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
export -f petsc
Then you can freely call your command from your scripts.
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
3
@Paul: I added"$@"
just to handle arguments.
– enzotib
Jan 26 '12 at 19:47
add a comment |
up vote
51
down vote
Aliases are deprecated in favor of shell functions. From the bash
manual page:
For almost every purpose, aliases are superseded by shell functions.
To create a function, and export it to subshells, put the following in your ~/.bashrc
:
petsc() {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
export -f petsc
Then you can freely call your command from your scripts.
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
3
@Paul: I added"$@"
just to handle arguments.
– enzotib
Jan 26 '12 at 19:47
add a comment |
up vote
51
down vote
up vote
51
down vote
Aliases are deprecated in favor of shell functions. From the bash
manual page:
For almost every purpose, aliases are superseded by shell functions.
To create a function, and export it to subshells, put the following in your ~/.bashrc
:
petsc() {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
export -f petsc
Then you can freely call your command from your scripts.
Aliases are deprecated in favor of shell functions. From the bash
manual page:
For almost every purpose, aliases are superseded by shell functions.
To create a function, and export it to subshells, put the following in your ~/.bashrc
:
petsc() {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
export -f petsc
Then you can freely call your command from your scripts.
edited Feb 1 '16 at 9:12
quest
1641111
1641111
answered Jan 26 '12 at 18:28
enzotib
62.4k6132154
62.4k6132154
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
3
@Paul: I added"$@"
just to handle arguments.
– enzotib
Jan 26 '12 at 19:47
add a comment |
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
3
@Paul: I added"$@"
just to handle arguments.
– enzotib
Jan 26 '12 at 19:47
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
That almost works... the only problem is that I need to be able to pass different flags to the executable "mpiexec"... For instance, I need to be able to execute something like "petsc -n 40 myexecutable" with the alias "petsc"
– Paul
Jan 26 '12 at 18:46
3
3
@Paul: I added
"$@"
just to handle arguments.– enzotib
Jan 26 '12 at 19:47
@Paul: I added
"$@"
just to handle arguments.– enzotib
Jan 26 '12 at 19:47
add a comment |
up vote
11
down vote
Shell functions and aliases are limited to the shell and do not work in executed shell scripts. Alternatives for your case:
(if you do not bother to use
mpiexec
instead ofpetsc
) Add$HOME/petsc-3.2-p6/petsc-arch/bin
to yourPATH
variable. This can be done by editing~/.profile
and appending:
PATH="$HOME/petsc-3.2-p6/petsc-arch/bin:$PATH"
Re-login to apply these changes
Create the directory
~/bin
and
make a wrapper script named
petsc
containing:
#!/bin/sh
exec ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
if the program allows for it, you can skip the shellscript and make a symlink using the command:
ln -s ~/petsc-3.2-p6/petsc-arch/bin/mpiexec ~/bin/petsc
add a comment |
up vote
11
down vote
Shell functions and aliases are limited to the shell and do not work in executed shell scripts. Alternatives for your case:
(if you do not bother to use
mpiexec
instead ofpetsc
) Add$HOME/petsc-3.2-p6/petsc-arch/bin
to yourPATH
variable. This can be done by editing~/.profile
and appending:
PATH="$HOME/petsc-3.2-p6/petsc-arch/bin:$PATH"
Re-login to apply these changes
Create the directory
~/bin
and
make a wrapper script named
petsc
containing:
#!/bin/sh
exec ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
if the program allows for it, you can skip the shellscript and make a symlink using the command:
ln -s ~/petsc-3.2-p6/petsc-arch/bin/mpiexec ~/bin/petsc
add a comment |
up vote
11
down vote
up vote
11
down vote
Shell functions and aliases are limited to the shell and do not work in executed shell scripts. Alternatives for your case:
(if you do not bother to use
mpiexec
instead ofpetsc
) Add$HOME/petsc-3.2-p6/petsc-arch/bin
to yourPATH
variable. This can be done by editing~/.profile
and appending:
PATH="$HOME/petsc-3.2-p6/petsc-arch/bin:$PATH"
Re-login to apply these changes
Create the directory
~/bin
and
make a wrapper script named
petsc
containing:
#!/bin/sh
exec ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
if the program allows for it, you can skip the shellscript and make a symlink using the command:
ln -s ~/petsc-3.2-p6/petsc-arch/bin/mpiexec ~/bin/petsc
Shell functions and aliases are limited to the shell and do not work in executed shell scripts. Alternatives for your case:
(if you do not bother to use
mpiexec
instead ofpetsc
) Add$HOME/petsc-3.2-p6/petsc-arch/bin
to yourPATH
variable. This can be done by editing~/.profile
and appending:
PATH="$HOME/petsc-3.2-p6/petsc-arch/bin:$PATH"
Re-login to apply these changes
Create the directory
~/bin
and
make a wrapper script named
petsc
containing:
#!/bin/sh
exec ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
if the program allows for it, you can skip the shellscript and make a symlink using the command:
ln -s ~/petsc-3.2-p6/petsc-arch/bin/mpiexec ~/bin/petsc
answered Jan 26 '12 at 18:52
Lekensteyn
120k48263354
120k48263354
add a comment |
add a comment |
up vote
7
down vote
In bash 4 you can use special variable: $BASH_ALIASES
.
For example:
$ alias foo="echo test"
$ echo ${BASH_ALIASES[foo]}
echo test
$ echo `${BASH_ALIASES[foo]}` bar
test bar
Alternatively define as variable then use command substitution or eval
.
So for example, instead of defining the alias such as:
alias foo="echo test"
define it as:
foo="echo test"
instead. Then execute it by either:
find . -type f -exec sh -c "eval $foo" ;
or:
find . -type f -exec sh -c "echo `$foo`" ;
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.
– erm3nda
Sep 16 '17 at 9:23
add a comment |
up vote
7
down vote
In bash 4 you can use special variable: $BASH_ALIASES
.
For example:
$ alias foo="echo test"
$ echo ${BASH_ALIASES[foo]}
echo test
$ echo `${BASH_ALIASES[foo]}` bar
test bar
Alternatively define as variable then use command substitution or eval
.
So for example, instead of defining the alias such as:
alias foo="echo test"
define it as:
foo="echo test"
instead. Then execute it by either:
find . -type f -exec sh -c "eval $foo" ;
or:
find . -type f -exec sh -c "echo `$foo`" ;
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.
– erm3nda
Sep 16 '17 at 9:23
add a comment |
up vote
7
down vote
up vote
7
down vote
In bash 4 you can use special variable: $BASH_ALIASES
.
For example:
$ alias foo="echo test"
$ echo ${BASH_ALIASES[foo]}
echo test
$ echo `${BASH_ALIASES[foo]}` bar
test bar
Alternatively define as variable then use command substitution or eval
.
So for example, instead of defining the alias such as:
alias foo="echo test"
define it as:
foo="echo test"
instead. Then execute it by either:
find . -type f -exec sh -c "eval $foo" ;
or:
find . -type f -exec sh -c "echo `$foo`" ;
In bash 4 you can use special variable: $BASH_ALIASES
.
For example:
$ alias foo="echo test"
$ echo ${BASH_ALIASES[foo]}
echo test
$ echo `${BASH_ALIASES[foo]}` bar
test bar
Alternatively define as variable then use command substitution or eval
.
So for example, instead of defining the alias such as:
alias foo="echo test"
define it as:
foo="echo test"
instead. Then execute it by either:
find . -type f -exec sh -c "eval $foo" ;
or:
find . -type f -exec sh -c "echo `$foo`" ;
edited Jun 1 '15 at 22:48
answered Jun 1 '15 at 22:31
kenorb
4,27913749
4,27913749
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.
– erm3nda
Sep 16 '17 at 9:23
add a comment |
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.
– erm3nda
Sep 16 '17 at 9:23
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the
${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.– erm3nda
Sep 16 '17 at 9:23
Altough aliases are deprecated in favor of shell functions, this answer os the only one which should be accepted. Even the old Debian 8 has version 4 of bash, so the
${BASH_ALIASES[alias]}
is a nice option. Otherwise i had to edit lot of lines of my .bash_aliases to apply other things. Thank you.– erm3nda
Sep 16 '17 at 9:23
add a comment |
up vote
4
down vote
In
.bash_aliases
:
petsc {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
Or put the function in
.bashrc
. Usually in.bashrc
only config settings ofbash
are stored.
In Terminal:
source .bash_aliases
- Call it:
petsc arg(s)
Advantage: you do not need export -f petsc
in .bash_aliases
. Aliases are deprecated but using .bash_aliases
for functions is ok.
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
add a comment |
up vote
4
down vote
In
.bash_aliases
:
petsc {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
Or put the function in
.bashrc
. Usually in.bashrc
only config settings ofbash
are stored.
In Terminal:
source .bash_aliases
- Call it:
petsc arg(s)
Advantage: you do not need export -f petsc
in .bash_aliases
. Aliases are deprecated but using .bash_aliases
for functions is ok.
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
add a comment |
up vote
4
down vote
up vote
4
down vote
In
.bash_aliases
:
petsc {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
Or put the function in
.bashrc
. Usually in.bashrc
only config settings ofbash
are stored.
In Terminal:
source .bash_aliases
- Call it:
petsc arg(s)
Advantage: you do not need export -f petsc
in .bash_aliases
. Aliases are deprecated but using .bash_aliases
for functions is ok.
In
.bash_aliases
:
petsc {
~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
}
Or put the function in
.bashrc
. Usually in.bashrc
only config settings ofbash
are stored.
In Terminal:
source .bash_aliases
- Call it:
petsc arg(s)
Advantage: you do not need export -f petsc
in .bash_aliases
. Aliases are deprecated but using .bash_aliases
for functions is ok.
edited Dec 2 at 12:08
muru
135k20289492
135k20289492
answered Mar 28 '15 at 9:07
Timo
1716
1716
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
add a comment |
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
I like this solution, I will give it a try later
– Greenonline
Apr 24 '15 at 2:24
add a comment |
up vote
3
down vote
You can force bash to execute your script as an interactive shell with the -i flag. This will tell your .bashrc file to define aliases and other functions.
Example:
~ $ grep ll .bashrc
alias ll='ls -lah'
~ $ cat script.sh
#!/bin/sh
ll
~ $ bash script.sh
script.sh: line 3: ll: command not found
~ $ bash -i script.sh
..directory contents..
More info:
$ man bash
2
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)
– muru
Jan 10 '17 at 13:12
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
add a comment |
up vote
3
down vote
You can force bash to execute your script as an interactive shell with the -i flag. This will tell your .bashrc file to define aliases and other functions.
Example:
~ $ grep ll .bashrc
alias ll='ls -lah'
~ $ cat script.sh
#!/bin/sh
ll
~ $ bash script.sh
script.sh: line 3: ll: command not found
~ $ bash -i script.sh
..directory contents..
More info:
$ man bash
2
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)
– muru
Jan 10 '17 at 13:12
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
add a comment |
up vote
3
down vote
up vote
3
down vote
You can force bash to execute your script as an interactive shell with the -i flag. This will tell your .bashrc file to define aliases and other functions.
Example:
~ $ grep ll .bashrc
alias ll='ls -lah'
~ $ cat script.sh
#!/bin/sh
ll
~ $ bash script.sh
script.sh: line 3: ll: command not found
~ $ bash -i script.sh
..directory contents..
More info:
$ man bash
You can force bash to execute your script as an interactive shell with the -i flag. This will tell your .bashrc file to define aliases and other functions.
Example:
~ $ grep ll .bashrc
alias ll='ls -lah'
~ $ cat script.sh
#!/bin/sh
ll
~ $ bash script.sh
script.sh: line 3: ll: command not found
~ $ bash -i script.sh
..directory contents..
More info:
$ man bash
edited Jan 10 '17 at 23:09
answered Jan 10 '17 at 8:03
Amado Martinez
1314
1314
2
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)
– muru
Jan 10 '17 at 13:12
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
add a comment |
2
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)
– muru
Jan 10 '17 at 13:12
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
2
2
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)– muru
Jan 10 '17 at 13:12
.bashrc
is also read during non-interactive SSH command execution (that's why it has a check for interactivity at the top)– muru
Jan 10 '17 at 13:12
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
I have edited my answer. Thanks @muru
– Amado Martinez
Jan 10 '17 at 23:10
add a comment |
up vote
2
down vote
- Use your aliases in your shell script.
- Source your script in your current, interactive shell instead of executing it.
So if you have a file called script.sh
with your commands that include using aliases, simply type:
source script.sh
@DavidFoerster This method works fine. Sourcing a script with the.
orsource
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which.
orsource
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.
– Eliah Kagan
Jan 10 '17 at 9:44
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
add a comment |
up vote
2
down vote
- Use your aliases in your shell script.
- Source your script in your current, interactive shell instead of executing it.
So if you have a file called script.sh
with your commands that include using aliases, simply type:
source script.sh
@DavidFoerster This method works fine. Sourcing a script with the.
orsource
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which.
orsource
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.
– Eliah Kagan
Jan 10 '17 at 9:44
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
add a comment |
up vote
2
down vote
up vote
2
down vote
- Use your aliases in your shell script.
- Source your script in your current, interactive shell instead of executing it.
So if you have a file called script.sh
with your commands that include using aliases, simply type:
source script.sh
- Use your aliases in your shell script.
- Source your script in your current, interactive shell instead of executing it.
So if you have a file called script.sh
with your commands that include using aliases, simply type:
source script.sh
edited Jan 10 '17 at 10:00
Eliah Kagan
81.1k20227364
81.1k20227364
answered Jul 25 '16 at 0:00
Gordon Erlebacher
211
211
@DavidFoerster This method works fine. Sourcing a script with the.
orsource
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which.
orsource
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.
– Eliah Kagan
Jan 10 '17 at 9:44
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
add a comment |
@DavidFoerster This method works fine. Sourcing a script with the.
orsource
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which.
orsource
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.
– Eliah Kagan
Jan 10 '17 at 9:44
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
@DavidFoerster This method works fine. Sourcing a script with the
.
or source
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which .
or source
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.– Eliah Kagan
Jan 10 '17 at 9:44
@DavidFoerster This method works fine. Sourcing a script with the
.
or source
buiiltin causes the current shell to execute all the commands in it. If alias expansion would occur in the shell in which .
or source
is run, it occurs. However, it's important to realize that this method is only sometimes useful, because often one needs or wants to execute a script in its own shell, with its own environment. Shell scripts written with the intention of being executed in the usual way should not usually be sourced instead--they often won't work right.– Eliah Kagan
Jan 10 '17 at 9:44
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
@EliahKagan: Thanks. Now I understand what the answer is supposed to mean. I'll add an explanation.
– David Foerster
Jan 10 '17 at 9:52
add a comment |
up vote
2
down vote
ALIASES
...
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS
below).
So the real answer to this question, for those looking to use actual aliases in shell scripts instead of alternatives to them, is:
#!/bin/bash
shopt -s expand_aliases
alias foo=bar
foo whatever
As for why I'd want to do this: Due to unusual circumstances, I need to trick a Dockerfile into thinking it's a shell script.
add a comment |
up vote
2
down vote
ALIASES
...
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS
below).
So the real answer to this question, for those looking to use actual aliases in shell scripts instead of alternatives to them, is:
#!/bin/bash
shopt -s expand_aliases
alias foo=bar
foo whatever
As for why I'd want to do this: Due to unusual circumstances, I need to trick a Dockerfile into thinking it's a shell script.
add a comment |
up vote
2
down vote
up vote
2
down vote
ALIASES
...
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS
below).
So the real answer to this question, for those looking to use actual aliases in shell scripts instead of alternatives to them, is:
#!/bin/bash
shopt -s expand_aliases
alias foo=bar
foo whatever
As for why I'd want to do this: Due to unusual circumstances, I need to trick a Dockerfile into thinking it's a shell script.
ALIASES
...
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS
below).
So the real answer to this question, for those looking to use actual aliases in shell scripts instead of alternatives to them, is:
#!/bin/bash
shopt -s expand_aliases
alias foo=bar
foo whatever
As for why I'd want to do this: Due to unusual circumstances, I need to trick a Dockerfile into thinking it's a shell script.
edited Jul 18 at 1:52
answered Jul 18 at 0:50
Jeremy Phelps
1213
1213
add a comment |
add a comment |
up vote
1
down vote
(EDIT: removed functions since I misread calling of mpiexec.)
If the only thing you need is less typing, why don't you just put the folder in $PATH? Or make a symlink to mpiexec from some folder in $PATH? Or (my favourite) put the alias in a script that you source in the calling script?
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
1
Cannot understand why not simply use"$@"
.
– enzotib
Jan 26 '12 at 19:49
2
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
add a comment |
up vote
1
down vote
(EDIT: removed functions since I misread calling of mpiexec.)
If the only thing you need is less typing, why don't you just put the folder in $PATH? Or make a symlink to mpiexec from some folder in $PATH? Or (my favourite) put the alias in a script that you source in the calling script?
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
1
Cannot understand why not simply use"$@"
.
– enzotib
Jan 26 '12 at 19:49
2
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
add a comment |
up vote
1
down vote
up vote
1
down vote
(EDIT: removed functions since I misread calling of mpiexec.)
If the only thing you need is less typing, why don't you just put the folder in $PATH? Or make a symlink to mpiexec from some folder in $PATH? Or (my favourite) put the alias in a script that you source in the calling script?
(EDIT: removed functions since I misread calling of mpiexec.)
If the only thing you need is less typing, why don't you just put the folder in $PATH? Or make a symlink to mpiexec from some folder in $PATH? Or (my favourite) put the alias in a script that you source in the calling script?
edited Jan 27 '12 at 9:46
answered Jan 26 '12 at 19:22
unhammer
1,39611732
1,39611732
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
1
Cannot understand why not simply use"$@"
.
– enzotib
Jan 26 '12 at 19:49
2
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
add a comment |
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
1
Cannot understand why not simply use"$@"
.
– enzotib
Jan 26 '12 at 19:49
2
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
The reason why I can't put it into my $PATH is because I have another 'mpiexec' file in another directory that is alredy in my $PATH. If I add the path to this new 'mpiexec', it will probably try to execute both of them... wouldn't it?
– Paul
Jan 26 '12 at 19:34
1
1
Cannot understand why not simply use
"$@"
.– enzotib
Jan 26 '12 at 19:49
Cannot understand why not simply use
"$@"
.– enzotib
Jan 26 '12 at 19:49
2
2
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
Paul, it'll try to execute the one that's first in the PATH, not both.
– unhammer
Jan 27 '12 at 9:41
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
enzotib, ah I misread the way mpiexec was called, I thought it needed all args as one. Will edit my answer :)
– unhammer
Jan 27 '12 at 9:44
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f98782%2fhow-to-run-an-alias-in-a-shell-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How about adding the alias to
.bash_aliases
? Also how about aliasing the absolute path instead of relative path likealias petsc='/home/user/petsc-3.2-p6/petsc-arch/bin/mpiexec'
– Nitin Venkatesh
Jan 26 '12 at 18:17
@nitstorm: Neither solution seems to work... I still get the same error as before
– Paul
Jan 26 '12 at 18:21
Related: unix.stackexchange.com/questions/1496/…
– AlikElzin-kilaka
Nov 27 at 4:03