How to create simple command line UI like the debian installer? [duplicate] - linux

This question already has answers here:
How to write a text mode gui in Linux? [closed]
(2 answers)
Closed 5 years ago.
Here's a screenshot of the debian installer
Can I use this with a simple command line command?
like:
sth --size 20x20 --title 'Debian Installer' --text 'I'm a Text'

Its made with ncurses. Most commonly used with C, altough you can get bindings for it to use with python, perl and alike.

There is also the whiptail command, if you only want to write a shell script (as the debian installer is).
There is a good page of it in the Bash Shell Scripting Book on WikiBooks:
https://en.wikibooks.org/wiki/Bash_Shell_Scripting/Whiptail

Related

How to write a script in python that can open a new linux terminal and do source automatically [duplicate]

This question already has answers here:
how to open a gnome terminal to execute a command with gnome-terminal, constantly?
(2 answers)
Closed 5 years ago.
I need to write a scirpt in python (or bash) which:
open a new linux terminal with a few tabs
do a 'source myfile.csh' command on each of the tab
I've tried with something like this:
os.system("gnome-terminal --tab --working-directory=/repo/ -e 'source myfile.csh' ")
but it didn't work (for example file was not found even though I was in a correct directory or can't open a .csh file blah blah blah)
I've also tried a few other options, but I didn't find a proper soultion for my problem.
I don't know why I can't do a simple "open a new terminal, write a command and execute it"
Maybe is there any simple solution WITHOUT installing any new software (I don't have a root)?
-e will execute a process. However source is an instruction of your shell. What you need to do is to call your shell with -e and pass arguments to the shell in order to execute the source instruction. Should be something like
os.system("gnome-terminal --tab --working-directory=/repo/ -e 'tcsh -c \"source myfile.csh\"'")

How to know the default shell process for my terminal? [duplicate]

This question already has answers here:
How to get the default shell
(5 answers)
Closed 6 years ago.
I am composing a bash script to serve as a utility tools.
The challenges I am facing now is:
- user using my tool will be running in bash environment
- however, some of them might default using krcsh or tcsh. they might have aliases or configurations set in there.
So, I need to prompt/guide user to resolve this during installation. My first challenge: How am I suppose to know the user's default shell within my install.sh?
Knowing the "default" shell, I can prompt and guide the user to do necessary transfer to bash.
my testing code:
my result:
1/ is fault obviously. It return the current shell which is my install.sh (bash)
2/ I am doubtful. It seems to be the history of what I have run before. It does not show me my default configured shell. My case, my terminal default shell is bash, and I run tsch for testing purpose. So the script parsed wrong information and will though my default shell is tcsh. It will then assist me to port configurations from tcsh to bash during the installation process.
If you want to check the shell you are using, you can use the following methods:
echo $0 in terminal will show you the program running if you want to check the shell you are currently using.
echo $SHELL - with this command you can read the user's default shell in the terminal you are running.
If you want to prompt, easily you can put the echo $SHELL in the part of your script where you need to show the current shell you are using.
Don't forget to put #!/bin/bash if your script is designed to run in a bash shell!

bash, reset terminal output as it was before [duplicate]

This question already has answers here:
Using the "alternate screen" in a bash script
(3 answers)
Closed 6 years ago.
I'm building a bash script, with an interactive ASCII-menu, and want it to restore the terminal as it was before, like "vim" does, or "less".
I guess, i have to redirect the output to an other shell or something like that. But all I have found, was for redirecting files, or opening new terminal windows.
You're looking for the ti and te terminal capabilities, which can be most easily accessed in bash (or on the command line) with the commands tput smcup to switch to the alternate screen and tput rmcup to restore the original screen.

Executable file from R code [duplicate]

This question already has an answer here:
What are the ways to create an executable from R program
(1 answer)
Closed 8 years ago.
I'm a master student, and I've a little problem with a script written in R.
How can I produce an executable file from it?
Should I use Linux (e.g.Ubuntu) or windows? I wrote a code in Windows, but I can use Ubuntu.
Using linux, you can run your Rscript from the command line (in the terminal like this)
Rscript <name of your Rscript file>

How to run multiple commands in Linux? Make a programm? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
First of all, I would like to let you know that I am new to Linux. I did my search, but I don't really know what it is that I am looking for.
What I need is to make a simple program, that executes different commands one after another in terminal, because I don't want to run them by hand every time I need it. How do I make it? I suppose I can't just make an executable file that would trigger on double click, or can I?
Update:
When I posted this question I was just a kid who somehow managed to install a Linux based OS. I didn't know anyone else who had Linux or anyone in CS for that matter. I didn't have anyone to ask the "stupid questions". I didn't know how to express myself. I was looking for a shell script guide, but all I found for "linux programming" was C, which was way out of my depth then.
The simple program you are referring to is usually called a "shell script". Essentially, you just collect a number of commands you want in a file, and execute them. You can also have some sort of flow control (loops, if-else statements etc) for more complex scripts.
To build a simple bash shell script, let's call it myscript.sh, follow these steps:
At the first line of the "myscript.sh" source file put (see Note below)
#!/bin/bash
then your commands, for instance for demonstration purposes
echo "hello, I'm coming from the script file"
ls -l
Save the file.
To make this file "executable" type
$ chmod +x myscript.sh
and then you should be able to run this file from the command line with
$ ./myscript.sh
You'd see the output of the echo command "hello, I'm coming from the script file", followed by a directory listing in long format.
Here are links for a bash tutorial and a Bash Guide for Beginners.
Finally, sometimes you can just string a couple of commands together using aliases, though most people just "alias" shorter versions of common commands creating abbreviations for commands.
Note re location of bash:
To find out where your bash shell is you can always type which bash, it will return a path/directory, so put that at the top if it's different. For instance if it says /usr/bin/bash you'd put #!/usr/bin/bashthat in place of #!/bin/bash as the first line of your script.
try writing a shell script:
#!/bin/bash
command1
command2 | grep 'something' | pager
foo | perl -ne 'print'
Save is as something.sh.
Mark it as executable with chmod +x something.sh.
Then cd to the directory where it resides and run ./something.sh.
Whether you can double-click start your script it depends on your configuration, but as most scripts create text output this doesn't often make sense. Use .desktop files to create shortcuts to a single (!) command (or whatever filetype your Desktop Environment (gnome/kde/xfce) perfers).
If your needs go beyond some simple bash, take a look at scripting languages like the object-oriented Python or the classic *nix administration language Perl.
View #Levon's post for further details.
What you are looking for is a script. The most common type are written in bash. A nice alternative is to write them in python.
Have a look for bash scripting examples to get you started, or look into http://www.diveintopython.net/ to start with Python

Resources