bash create another shell interface - gnome-shell-extensions

in a bash script, inserting an & will create a child process in which to run the command.
Is it possible to run a gnome-shell, or other windowed interface, in which to run a command?

Related

Calling bash from within R

I have R generating some .csv files for another python program to run in another folder, I know it is possible to call bash from R but how could I call the command make in my ubuntu virtual machine in another directory?
The simple way is creating an script to cd to your dir and exec make after that
script <- tempfile()
fhandle <- file(script)
writeLines("( cd /your_directory && make )",con=fhandle)
system2("/bin/bash",args=c(script))
You may need to find the correct path to /bin/bash, mine is from MacOs
You can work with system2 parameters to control what happens with output from make command and if you want to run the process in parallel with your R task or wait for completion.

Schedule multiple R scripts to run sequentially

I have multiple scripts naming R001.r, R002.r, and so on. I need to schedule them so that they run in a sequential manner one after the other. What would be the best approach to do this.
I think you want to wrap your r scripts in a caller sh file and then invoke it through terminal. Here is what I would do.
Open up a terminal or any text editor available and fill it up with the following commands:
Rscript R0001.r
Rscript R0002.r
Rscript R0003.r
...
Save this file into something like call_my_scripts. You can then execute it via standard unix shell commands as follows:
./call_my_scripts
This will run sequentially by definition. Make sure you give exec permissions to the file before you invoke it as follows:
chmod u+x call_my_scripts

Write a file using System Command

I am trying to create a file using the system command but it does not work for some reason. It just echoes the command back.
system("echo 'Hello2222, world.' >foo2.txt");
Hello2222, world. >foo2.txt
When I run the echo command in CMD, the file is created.
Notice that the documentation for system says
On Windows, system does not use a shell and there is a separate
function shell which passes command lines to a shell.
shell("echo 'Hello2222, world.' >foo2.txt")
will do what you want.

Command line app: Unix cd command

My Mac OS command line application is making Unix calls such as:
system("rm -rf /Users/stu/Developer/file);
perfectly successfully.
So why is the following not changing the current directory?
system("cd /Users/me/whatever");
system("pwd"); //cd has not changed
Because
system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed.
So each command is executed independently, each in a new instance of the shell.
So your first call spawns a new sh (with your current working directory), changes directories, and then exits. Then the second call spawns a new sh (again in your CWD).
See the man page for system().
The better solution is to not use system. It has some inherent flaws that can leave you open to security vulnerabilities. Instead of executing system() commands, you should use the equivalent POSIX C functions. Everything that you can do from the command-line, you can do with C functions (how do you think those utilities work?)
Instead of system("rm -rf ...") use this.
Instead of system("cd ...") use chdir().
Instead of system("pwd ...") use getcwd().
There are some differences, of course, but these are the fundamental equivalents of what you're trying to do.

Running a command for every new window in tmux

I wrote this thing and I'd like to source a Python virtualenv activate script whenever a new window is created in a running session.
Is it possible? The default-command option is related to the shell, not an additional command.
I am making the following assumptions:
You are using bash
Your .bashrc file is source for each new window that starts a shell
You only want to start your virtualenv in a window that runs a shell
Add the code you want to run to your .bashrc:
if [[ $TMUX ]]; then
# code here
fi
This code will only run for new shells which are in an existing tmux session.

Resources