Create commands in terminal for executing own program and its commands - terminal

I was wondering how to configure a program (for example written in Python) so i can run it from the terminal (Ubuntu) and its commands, without using an alias.
For example:
$myprogram dosomething
and that should execute the code which refers to dosomething
Thank you very much!

Related

How to run bash script from macro shell?

How can I create a macro (for instance LibreOffice calc) that runs a bash script in terminal (for instance xfce4-terminal). An example:
#!/bin/bash
echo "Hello world"
echo "Press any key to close this window"
read
I tried the Shell command in macro editor, but nothing happened. Here is what I did:
Sub testMysql
Shell ("/mnt/save/janos/home/testbashsql",4)
end Sub
It compiles and runs without error, but no output. As a side question: what does "compile" mean in this context, i.e. what happens to the compiled code? where is it stored? Why is there a "compile" button?
Thanks for helping me better understand macros.
Calling the script will execute the script in a shell. To see results, the script should write to a file rather than stdout, because LibreOffice does not display stdout.
To open a terminal instead, call the terminal. This worked on my system.
Shell("xterm")
Regarding the compile button in the LO IDE, I use it to check Basic code for any syntax errors. I am not aware of any compiled stored code. Documentation is at https://help.libreoffice.org/Basic/Compile.

Calling two functions in Windows batch file one after the other

I have two scripts which are to be executed and i am using Windows batch script for automating of running the scripts.
I have to read 10 user input values and then run the two scripts using those parameters.
I am successful in executing the first script and failing with the second script.
Issue is that the cmd prompt exits after completing the first script.
How to make cmd prompt run the second script as well using the input parameters.
Any Help on this??
Thanks in Advance.
You have two options to execute a batch script from you code. It's either START or CALL:
START will execute your code in it's own variable scope, means the variables you've set in the first script won't be available. Further both scripts will be executed in parallel and not one after another (unless you use START /WAIT).
CALL on the other hand will do exactly what you need. It will start the first script in the same scope (previously set variables are variable), execute it and afterwards it will run the second sript (also in the same scope).
TL;DR this will work:
...
CALL BatchScript1.bat
CALL BatchScript2.bat
...
If you call scripts from another script you have to use the call command:
#echo off
call first.cmd
call second.bat
echo Here I'm back again !

How to read from terminal in lazarus on ubuntu

Lazarus can run bash scripts and commands. How to get the output of an executed command as string and later use it, for example print it with ShowMessage? Thanks!
Summary:
use the tprocess class from unit process, that allows to trap console output using pipes.
for straightforward cases use the Runcommand helper functions (also in process, wrap tprocess for simple cases)
Be aware that while you see console output as one stream, in fact there might be two (stdout and stderr)

How to link shared library in shell script?

I have wrote a simple shell script where I have only mentioned the following line
export LD_LIBRARY_PATH=/home/lib/
I want to run one program for which I have to link with this library ,before running the program I am running this shell script ,but after this the program is not working it showing the linking error and when I am doing following line it showing nothing
echo $LD_LIBRARY_PATH
but,when I am doing it in shell normally ,it is working.
Can any one tell why this shell script is not working.what is the concept behind it.
Thanks
If you want to run a script for the purpose of modifying environment variables you need to source the script rather than run the script. Running the script starts a new instance of w/e shell is used to run the script, when it returns, all environment variables are back to the way they were before you ran it. Doing "source script.sh" actually runs the commands in the script in your current shell.

How to call bash commands from tcl script?

Bash commands are available from an interactive tclsh session. E.g. in a tclsh session you can have
% ls
instead of
$ exec ls
However, you cant have a tcl script which calls bash commands directly (i.e. without exec).
How can I make tclsh to recognize bash commands while interpreting tcl script files, just like it does in an interactive session?
I guess there is some tcl package (or something like that), which is being loaded automatically while launching an interactive session to support direct calls of bash commans. How can I load it manually in tcl script files?
If you want to have specific utilities available in your scripts, write bridging procedures:
proc ls args {
exec {*}[auto_execok ls] {*}$args
}
That will even work (with obvious adaptation) for most shell builtins or on Windows. (To be fair, you usually don't want to use an external ls; the internal glob command usually suffices, sometimes with extra help from some file subcommands.) Some commands need a little more work (e.g., redirecting input so it comes from the terminal, with an extra <#stdin or </dev/tty; that's needed for stty on some platforms) but that works reasonably well.
However, if what you're asking for is to have arbitrary execution of external programs without any extra code to mark that they are external, that's considered to be against the ethos of Tcl. The issue is that it makes the code quite a lot harder to maintain; it's not obvious that you're doing an expensive call-out instead of using something (relatively) cheap that's internal. Putting in the exec in that case isn't that onerous…
What's going on here is that the unknown proc is getting invoked when you type a command like ls, because that's not an existing tcl command, and by default, that command will check that if the command was invoked from an interactive session and from the top-level (not indirectly in a proc body) and it's checking to see if the proc name exists somewhere on the path. You can get something like this by writing your own proc unknown.
For a good start on this, examine the output of
info body unknown
One thing you should know is that ls is not a Bash command. It's a standalone utility. The clue for how tclsh runs such utilities is right there in its name - sh means "shell". So it's the rough equivalent to Bash in that Bash is also a shell. Tcl != tclsh so you have to use exec.

Resources