running several comands in a bash script [duplicate]












0















This question already has an answer here:




  • Alias doesn't work inside a Bash script

    2 answers




I have some commands I would like to run in the following order:



HEADAS=/home/warano/HEASoft/heasoft-6.24/x86_64-pc-linux-gnu-libc2.27
export HEADAS
alias heainit=". $HEADAS/headas-init.sh"
heainit
CALDB=/home/warano/NUSTAR/caldb
export CALDB
source $CALDB/software/tools/caldbinit.sh


I put all of these in a script called run-nu_tools.sh, but it does not work so I got this output:



./run-nu_tools.sh: line 6: heainit: command not found


However heainit works if one runs everything in the terminal(step by step) so I want to run all at once, do you have any tips?










share|improve this question













marked as duplicate by kvantour, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Aliases suck anyway. Use a function.
    – tripleee
    Nov 12 at 10:57










  • This does not help at all.
    – Wara
    Nov 12 at 11:07










  • Why do you say it does not help? Why do you not want to use a function? Why do you want to use an alias? What happens if you use a function anyway?
    – tripleee
    Nov 12 at 11:08
















0















This question already has an answer here:




  • Alias doesn't work inside a Bash script

    2 answers




I have some commands I would like to run in the following order:



HEADAS=/home/warano/HEASoft/heasoft-6.24/x86_64-pc-linux-gnu-libc2.27
export HEADAS
alias heainit=". $HEADAS/headas-init.sh"
heainit
CALDB=/home/warano/NUSTAR/caldb
export CALDB
source $CALDB/software/tools/caldbinit.sh


I put all of these in a script called run-nu_tools.sh, but it does not work so I got this output:



./run-nu_tools.sh: line 6: heainit: command not found


However heainit works if one runs everything in the terminal(step by step) so I want to run all at once, do you have any tips?










share|improve this question













marked as duplicate by kvantour, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Aliases suck anyway. Use a function.
    – tripleee
    Nov 12 at 10:57










  • This does not help at all.
    – Wara
    Nov 12 at 11:07










  • Why do you say it does not help? Why do you not want to use a function? Why do you want to use an alias? What happens if you use a function anyway?
    – tripleee
    Nov 12 at 11:08














0












0








0


1






This question already has an answer here:




  • Alias doesn't work inside a Bash script

    2 answers




I have some commands I would like to run in the following order:



HEADAS=/home/warano/HEASoft/heasoft-6.24/x86_64-pc-linux-gnu-libc2.27
export HEADAS
alias heainit=". $HEADAS/headas-init.sh"
heainit
CALDB=/home/warano/NUSTAR/caldb
export CALDB
source $CALDB/software/tools/caldbinit.sh


I put all of these in a script called run-nu_tools.sh, but it does not work so I got this output:



./run-nu_tools.sh: line 6: heainit: command not found


However heainit works if one runs everything in the terminal(step by step) so I want to run all at once, do you have any tips?










share|improve this question














This question already has an answer here:




  • Alias doesn't work inside a Bash script

    2 answers




I have some commands I would like to run in the following order:



HEADAS=/home/warano/HEASoft/heasoft-6.24/x86_64-pc-linux-gnu-libc2.27
export HEADAS
alias heainit=". $HEADAS/headas-init.sh"
heainit
CALDB=/home/warano/NUSTAR/caldb
export CALDB
source $CALDB/software/tools/caldbinit.sh


I put all of these in a script called run-nu_tools.sh, but it does not work so I got this output:



./run-nu_tools.sh: line 6: heainit: command not found


However heainit works if one runs everything in the terminal(step by step) so I want to run all at once, do you have any tips?





This question already has an answer here:




  • Alias doesn't work inside a Bash script

    2 answers








bash scripting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 10:40









Wara

586




586




marked as duplicate by kvantour, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by kvantour, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Aliases suck anyway. Use a function.
    – tripleee
    Nov 12 at 10:57










  • This does not help at all.
    – Wara
    Nov 12 at 11:07










  • Why do you say it does not help? Why do you not want to use a function? Why do you want to use an alias? What happens if you use a function anyway?
    – tripleee
    Nov 12 at 11:08


















  • Aliases suck anyway. Use a function.
    – tripleee
    Nov 12 at 10:57










  • This does not help at all.
    – Wara
    Nov 12 at 11:07










  • Why do you say it does not help? Why do you not want to use a function? Why do you want to use an alias? What happens if you use a function anyway?
    – tripleee
    Nov 12 at 11:08
















Aliases suck anyway. Use a function.
– tripleee
Nov 12 at 10:57




Aliases suck anyway. Use a function.
– tripleee
Nov 12 at 10:57












This does not help at all.
– Wara
Nov 12 at 11:07




This does not help at all.
– Wara
Nov 12 at 11:07












Why do you say it does not help? Why do you not want to use a function? Why do you want to use an alias? What happens if you use a function anyway?
– tripleee
Nov 12 at 11:08




Why do you say it does not help? Why do you not want to use a function? Why do you want to use an alias? What happens if you use a function anyway?
– tripleee
Nov 12 at 11:08












1 Answer
1






active

oldest

votes


















2














The problem is that aliases are not expanded if the shell is not interactive:




ALIASES: Aliases are not expanded when the shell is not interactive unless the expand_aliases shell option is set using shopt.



source: man bash




Add the following to your script:



shopt -s expand_aliases





share|improve this answer























  • It does not work.
    – Wara
    Nov 12 at 10:57










  • If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
    – tripleee
    Nov 12 at 11:13


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The problem is that aliases are not expanded if the shell is not interactive:




ALIASES: Aliases are not expanded when the shell is not interactive unless the expand_aliases shell option is set using shopt.



source: man bash




Add the following to your script:



shopt -s expand_aliases





share|improve this answer























  • It does not work.
    – Wara
    Nov 12 at 10:57










  • If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
    – tripleee
    Nov 12 at 11:13
















2














The problem is that aliases are not expanded if the shell is not interactive:




ALIASES: Aliases are not expanded when the shell is not interactive unless the expand_aliases shell option is set using shopt.



source: man bash




Add the following to your script:



shopt -s expand_aliases





share|improve this answer























  • It does not work.
    – Wara
    Nov 12 at 10:57










  • If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
    – tripleee
    Nov 12 at 11:13














2












2








2






The problem is that aliases are not expanded if the shell is not interactive:




ALIASES: Aliases are not expanded when the shell is not interactive unless the expand_aliases shell option is set using shopt.



source: man bash




Add the following to your script:



shopt -s expand_aliases





share|improve this answer














The problem is that aliases are not expanded if the shell is not interactive:




ALIASES: Aliases are not expanded when the shell is not interactive unless the expand_aliases shell option is set using shopt.



source: man bash




Add the following to your script:



shopt -s expand_aliases






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 10:51

























answered Nov 12 at 10:46









kvantour

7,89331129




7,89331129












  • It does not work.
    – Wara
    Nov 12 at 10:57










  • If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
    – tripleee
    Nov 12 at 11:13


















  • It does not work.
    – Wara
    Nov 12 at 10:57










  • If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
    – tripleee
    Nov 12 at 11:13
















It does not work.
– Wara
Nov 12 at 10:57




It does not work.
– Wara
Nov 12 at 10:57












If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
– tripleee
Nov 12 at 11:13




If it doesn't work for you, some part of the prerequisites is wrong. Are you not using Bash after all, perhaps? See also stackoverflow.com/questions/5725296/…
– tripleee
Nov 12 at 11:13



Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values