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.
#!/bin/bash
#Frame
. "/uhost/admin/uhost_files/UHU_FRAME.source"
. "/uhost/admin/uhost_files/UHU_DIR_EXECUTE.source"
arr_uhu_arg=("$@")
command_get="$1"
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
fi
}
if [[ "$command_get" == "init_help" ]]; then
Help # Runs Help function when used by the help command
else
Start # Runs the main command's function
fi
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
fi
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
EDIT #1
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"`
to
/bin/bash ${UHU_DIR_EXECUTE}/com/$uhu_sepcommand "$uhu_sepcommand_arg1" "$uhu_sepcommand_arg2"
solves the problem.
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 'SO- stop being evil' Jan 01 '15 at 22:50/bin/bash SOMESCRIPT
solved it. – Kessie Heldieheren Jan 02 '15 at 13:15