I would like to run a python script multiple times in a new terminal each time so I am making a bash script to do this.
#!/bin/bash
alias bot_1="cd ../Folder1"
alias bot_2="cd ../Folder2"
gnome-terminal
bot_1
python3 bot_one.py
gnome-terminal
bot_2
python3 bot_two.py
I would like to run a python script multiple times in a new terminal each time so I am making a bash script to do this.
With my script I have a new terminal which opens but the following commands are executed in the old and not the new
gnome-terminal has the ability to execute a command other than the default interactive shell.
gnome-terminal --working-directory ../Folder1 -- python3 bot_one.py
gnome-terminal --working-directory ../Folder2 -- python3 bot_two.py
Related
I want to write a script for Ubuntu, which open a terminal-emulator, which only allows users interact with it only once. After finish running user's first command typed in, the terminal close on itself automatically, which is kind of like Win+R on windows OS.
How should I do that?
I try script like gnome-terminal -- bash -c "read cmd && $cmd", but there's two problem:
No auto-complete on user inputting commands;
Commands from .bashrc, .bash_aliases are not recognized.
You can try :
gnome-terminal -- bash --rcfile <(cat ~/.bashrc; echo 'PROMPT_COMMAND="PROMPT_COMMAND=exit"')
I don't have Ubuntu to test at the moment, but bash ... part worked.
I had the bash script where in I had to launch the application ide command and then the >>> appears in the terminal where in I had to execute the commands such as in script file
#!/bin/bash
OMShell-terminal
loadModel(Modelica)
loadFile("Filename")
simulate(filename, startTime, stopTime)
but after loading the OMShell-terminal I will get the >>>to input the commands here but the shell script would not let me to input the commands here from shell script itself what modification I should do please guide.
I need some help:
(On macos, bash shell)
If I run a .sh file which calls e.g. exit 1 (any exit code) my terminal session ends (and the iterm2 tab/window closes).
I'm calling the script like this $ . myscript.sh
I'm pretty sure it should not be like that or was not like this a while before.
Using:
. myscript.sh
You are actually running the script in the existing shell or "sourcing" the script. With exit at the end of the script, this means that the terminal session will also exit
Alternatively:
./myscript.sh
or
bash myscript.sh
Will run the script in a separate bash shell and stop the terminal session from exiting.
Instead of . myscript.sh you can run ./myscript.sh which will run it in a separate bash shell and will not exit the current session.
If you control the content of this .sh file, and you do want to source the script - simply return 1 instead of exit 1, and use proper error handling.
I want to replace complex commands with simple characters and execute in background, so I can shut down the terminal.
The command is nWave -ssf test.fsdb(fsdb is a wavefile). In bashrc, I write alias nwave='nWave -ssf'.
If I want the command to be executed in background, I use nWave -ssf test.fsdb &. How to realize this command when using alias in bashrc file.
If you plan to close the terminal, you probably want to wrap the command in nohup. However, using 'nohup alias ...' will not work - as nohup only accept regular command. You can embed the nohup into the alias explicitly.
# In bashrc
alias bgnwave 'nohup nWave -ssf'
# At the terminal
bgnware test.fsdb &
As an alternative to bash alias, consider using bash function
function bgwnwave {
nohup nWave -ssf "$#" &
}
My default shell is bash. I have set some environment variables in my .bashrc file.
I installed a program which use .cshrc file. It contains the path to several cshell scripts.
When I run the following commands in the shell windows it works perfectly :
exec csh
source .cshrc
exec bash
I have tried to put these commands in bash script, unfortunately it didn't work.
is there another way to write a script in order to get the same result as running commands from a shell windows.
I hope my question is now clear
Many thanks for any help
WARNING : don't put the following script in your .bashrc, it will reload bash and so reload .bashrc again and again (stopable with C-c anyway)
Use preferable this script in your kit/CDS stuff startup script. (cadence presumably)
WARNING 2 : if anything in your file2source fails, the whole 'trick' stops.
Call this script : cshWrapper.csh
#! /bin/csh
# to launch using
# exec cshWrapper.csh file2source.sh
source $1
exec $SHELL -i
and launch it using
exec ./cshWrapper.csh file2source.sh
it will : launch csh, source your file and came back to the same parrent bash shell
Example :
$> ps
PID TTY TIME CMD
7065 pts/0 00:00:02 bash
$>exec ./cshWrapper.csh toggle.csh
file sourced
1
$> echo $$
7065
where in my case i use the file toggle.csh
#! /bin/csh
# source ./toggle.csh
if ! $?TOGGLE then
setenv TOGGLE 0
endif
if ($?TOGGLE) then
echo 'file sourced'
if ($TOGGLE == 0) then
setenv TOGGLE 1
else
setenv TOGGLE 0
endif
endif
echo $TOGGLE
Hope it helps
New proposal, since I faced another problem with exec.
exec kills whatever remains in the script, except if you force a fork by using a pipe after it `exec script |cat'. In such case if you have environment variable in the script, they are not spread back to the script itself, which is not what we want. The only solution I found is to use 3 files (let's call them for the example : main.bash that call first.cshrc and second.sh).
#! /bin/bash
#_main.bash_
exec /bin/csh -c "source /path_to_file/cshrc; exec /bin/bash -i -c /path_to_file/second.sh"
# after exec nothing remains (like Attila the Hun)
# the rest of the script is in 'second.sh'
With that manner, i can launch in a single script call, an old cshrc design kit, and still process some bash command after, and finally launch the main program in bash (let say virtuoso)