I appear to be having unexplainable issues with scripts run from within a subscript. I've been unable to acquire a solution so I will give you what I can to help me solve it.

Problem: when a script is run from within a script, particular glitches occur that do not when running the script from the main shell, e.g.

# ./user

The glitches that occur are that all 'echo' statement prints onto the same line, even given \n with '-e', '-n', or nothing at all. The other main glitch is that the 'read' statement in the code actually gets run before everything else, when it's one of the last things run in the debug code, from within the subscript.

Below is the code being executed from within the main script.


. "/uhost/admin/uhost_files/UHU_FRAME.source"
. "/uhost/admin/uhost_files/UHU_DIR_EXECUTE.source"


function Help () {
    echo -e -n "Allows creation, edition, and locking of user accounts stored on the UH2 system.\n"
    echo -e -n "Takes the following arguments: ${lblue} add lock del${nc}\n"
    echo -e -n "Can add, lock, and delete UNIX user accounts from the UH2 system.\n"

function Start () {
    if [[ " ${arr_uhu_arg[*]} " == *" add "* ]]; then
        echo "===== USER ADD ====="
        echo "Username: "
        read uhost_username

if [[ "$command_get" == "init_help" ]]; then
    Help # Runs Help function when used by the help command
    Start # Runs the main command's function

The scripts are called via the line in the main script:

echo `/bin/bash ${UHU_DIR_EXECUTE}/com/$uhu_sepcommand "$uhu_sepcommand_arg1" "$uhu_sepcommand_arg2"`

'$uhu_sepcommand' is the script file, followed by arguments.

The part

if [[ " ${arr_uhu_arg[*]} " == *" add "* ]]; then
        echo "===== USER ADD ====="
        echo "Username: "
        read uhost_username

Both 'echo' statements appear on one line, and the 'read' statement seems to execute before everything else.

The glitches ONLY occur when executing the script from within the main script.

Using GNU bash, version 4.2.37(1)-release (i486-pc-linux-gnu)

Debian GNU/Linux 7.7


The comment by Gilles actually answers my problem. The subscript was being accumulated all together and output as one 'lump'. To clarify, the glitch was output coming out inconsistently and incorrectly to what was written. Changing

echo `/bin/bash ${UHU_DIR_EXECUTE}/com/$uhu_sepcommand "$uhu_sepcommand_arg1" "$uhu_sepcommand_arg2"`


/bin/bash ${UHU_DIR_EXECUTE}/com/$uhu_sepcommand "$uhu_sepcommand_arg1" "$uhu_sepcommand_arg2"

solves the problem.

closed as unclear what you're asking by Gilles, Networker, jimmij, slm Jan 2 '15 at 0:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Your question is inconsistent. You say that the problem comes when a script is executed by another script, and then you say that the problem is in the main script. Please clarify your question: post some code that we could run our our machine to reproduce the problem. Do note that echo `/bin/bash SOMESCRIPT …` does not print the output of SOMESCRIPT like running it directly, it accumulates the output into an internal variable and then prints the expanded result in one lump, which sounds like your problem. – Gilles Jan 1 '15 at 22:50
  • I was about to post a solution. the problem is that the $( ... ) wont produce output inthil the contained command has completed. the fix is to use stderr where output needs to go to the user. – Jasen Jan 2 '15 at 1:02
  • @Gilles You actually answered my problem. I shouldn't have used 'echo' and I didn't realise that was wrong. Treating it as solely a command alone, i.e. /bin/bash SOMESCRIPT solved it. – Kessie Heldieheren Jan 2 '15 at 13:15

Browse other questions tagged or ask your own question.