How to link shared library in shell script? - shell

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.

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 another scripts to run in current script

I'm writing a shell script. what it does is it will create a file by the input that is received from the user. Now, i want to add the feature called "view a file" for my current script. Now, it's unreasonal to retype it again since i've already had a script that helps
I know it's crazy when it is possible to it with normal shell command. I'm actually writing a script that help me to create pages that are generated from the touch command. (this pages had attached date, author name, subjects, and title).
The question is how to call a another script or inhere another script?
Couple of ways to do this. My prefered way is by using source
You can -
Call your other script with the source command (alias is .) like this: source /path/to/script.
Make the other script executable, add the #!/bin/bash line at the top, and the path where the file is to the $PATH environment variable. Then you can call it as a normal command.
Use the bash command to execute it: /bin/bash /path/to/script

Getting continuous output from shell script that is run by Applescript in Cocoa

I have a shell script that is using echo to give a continuous output (the progress of an rsync) that I am using AppleScript to run with administrator privileges. Before I was using NSTask to run the shell script, but I couldn't find a way to run it with the privileges that it needed, so now I am using applescript to run it. When it was running via NSTask, I could use an output pipe and waitForDataInbackgroundAndNotify to get the continuous output and put it into a text field, but now that I am using AppleScript, I cannot seem to find a way to accomplish this. The shell script is still using echo, but it seems to get lost in the AppleScript "wrapper." How do I make sure that the AppleScript sees the output from the shell script and passes it on to the application? Remember, this isn't one single output, but continuous output.
Zero is correct. When you use do shell script, you can consider it similar to using backticks in perl. The command will be executed, and the everything sent to STDOUT will be returned as the result.
The only work around would be to have the your command write the output to a temporary file and then use do shell script "foo" without waiting. From there, you can read from the file sequentially using native AppleScript commands. It's clunky, but it'll work in a pinch.

Redirect bash output called from batch file to console

I have a batch file (build.bat) which calls a bash script (makelibs.sh). The bash script contains several commands which build 20 libraries from source.
If I run makelibs.sh from MSYS, I get continuous output. If I call it from the batch file, then I see the full output only at the end of every single command.
This makes it difficult to assess the current status of the process.
Is it possible to redirect the output of makelibs.sh in order to get a continuous feedback on the execution?
I have a batch file (build.bat) which calls a bash script (makelibs.sh)
I strongly advise against doing this. You are calling a script with a script, when you could simply open up Bash and put
makelibs.sh
However if you insist on doing this then perhaps start would work
start bash.exe makelibs.sh
ref

run command in parent shell from ruby

I'm trying to change the directory of the shell I start the ruby script form via the ruby script itself...
My point is to build a little program to manage favorites directories and easily change among them.
Here's what I did
#!/usr/bin/ruby
Dir.chdir("/Users/luca/mydir")
and than tried executing it in many ways...
my_script (this doesn't change the directory)
. my_script (this is interpreted as bash)
. $(ruby my_script) (this is interpreted as bash too!)
any idea?
Cannot be done. Child processes cannot modify their parents environment (including the current working directory of the parent). The . (also known as source) trick only works with shell scripts because you are telling the shell to run that code in the current process (rather than spawning a subprocess to run it). Just for fun try putting exit in a file you run this way (spoiler: you will get logged out).
If you wish to have the illusion of this working you need to create shell functions that call your Ruby script and have the shell function do the actual cd. Since the functions run in the current process, they can change the directory. For instance, given this ruby script (named temp.rb):
#!/usr/bin/ruby
print "/tmp";
You could write this BASH function (in, say, you ~/.profile):
function gotmp {
cd $(~/bin/temp.rb)
}
And then you could say gotmp at the commandline and have the directory be changed.
#!/usr/bin/env ruby
`../your_script`
Like this?
Or start your script in the directory you want it to do something.
Maybe I don't get your question. Provide some more details.

Resources