cygwin and startup command
One of the most asked questions related to bash is: ‘How to run some command on startup and leave bash run interactively?’
The simplest thing with cmd.exe
- /k
switch, but the bash has no equivalent.
Of course, the question is not related to ConEmu, but let options be here.
All examples below suppose that bash.exe
exists in your %PATH%
.
Modify your ~/.bashrc
The example lines were copied from SU question.
You need to modify your ~/.bashrc
profile script adding at the end:
[[ $STARTUP_CMD ]] && {
declare +x STARTUP_CMD
eval "$STARTUP_CMD"
unset STARTUP_CMD
}
Or, if previous snippet does not work (msys1 does not have locale
):
if [[ -n "${STARTUP_CMD}" ]]; then
$STARTUP_CMD
unset STARTUP_CMD
fi
And configure your ConEmu’s task like following:
set "STARTUP_CMD=echo 'This is sample command' && echo 'And this is another command'" && bash -l -i
NB It’s recommended to use upper-case variable name. Some versions have ignored lower-case or camel-case variable names.
Piping ~/.bashrc copy
Solution from StackOverflow:
bash --rcfile <(echo '. ~/.bashrc; some_command')
No modifications of original ~/.bashrc
are required, just take care of properly
escaped special symbols (single quote) in some_command
.
Use command conveyers
This method supposed that your command will be executed before your login shell have to be started. And there is overhead because your login script is to be executed twice actually.
bash -l -i -c "echo 'This is sample command' && echo 'And this is another command' && bash -l -i"
Use GuiMacro and command conveyers
You may use GuiMacro function print
to post some command into console input buffer after console starts.
You still need to use conveyer to run ConEmuC
before bash
.
NB The \n
is appended to press Enter
automatically.
cmd /c "ConEmuC -Silent -GuiMacro print "echo 'This is sample command' && echo 'And this is another command'\n" && bash -l -i"