LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-10-2008, 04:35 AM   #1
mrsvan
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Rep: Reputation: 0
how to execute bash-script from .bashrc


Im trying to make a little toolbox and for this I want to execute a script from .bashrc that writes a gnuplot file::

#!/bin/bash
echo 'set output' > pairwise.gp
echo "plot '" $1 "' u 1:2 w lp, '" $1 "' u 3:4 w lp" >> pairwise.gp

If I dont redirect the echo "" to a file, I get the output. If I execute the script with "./script test" from my current dir the file is executed properly.
I cannot execute the script properly from another dir when writing
/path/to/script test

Im wondering if I should just write
execute /path/to/script test
but Im running out of options
 
Old 07-10-2008, 06:52 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Hello and welcome to LQ.

Quote:
Originally Posted by mrsvan View Post
Im trying to make a little toolbox and for this I want to execute a script from .bashrc that writes a gnuplot file
Bash, regardless of it being an interactive login or non-interactive shell, when invoked as '/bin/bash', will source ~/.bashrc unless expressly prohibited or otherwise so configured. So scripts that do not have any bearing on the login process should not be executed from your Bash resource files.


Quote:
Originally Posted by mrsvan View Post
test -d ~/tmp || mkdir ~/tmp; echo 'set output' > ~/tmp/pairwise.gp
echo "plot '" $1 "' u 1:2 w lp, '" $1 "' u 3:4 w lp" >> ~/tmp/pairwise.gp
While it's better to use 'mktemp', and unless overwriting is OK, if you don't you should at least test for existence of your output file and make sure the output goes to some temporary or other work directory or it'll end up in $PWD which could litter your filesystem with output files.


Quote:
Originally Posted by mrsvan View Post
If I dont redirect the echo "" to a file, I get the output.
I don't know this "set output" option? Not that that means anything of course...


Quote:
Originally Posted by mrsvan View Post
I cannot execute the script properly from another dir when writing /path/to/script test
Maybe because you need to provide the location of "test" and execute it as '/path/to/script /path/to/test'?
 
Old 07-11-2008, 01:52 AM   #3
mrsvan
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Original Poster
Rep: Reputation: 0
I think I can boil the problem down to the script

Code:
echo "something"
echo "something else" > pairwise.gp
when I call the script using /path/to/script I get the output 'something' in my konsole.
When I cd /path/to/script and type ./script I both get the output 'something' in my console and a file named 'pairwise.gp' with 'something else' written in it.

* The
Code:
set output
command is for making sure that I get the default output from gnuplot and not some .eps file
 
Old 07-21-2008, 07:26 AM   #4
hrsvan
LQ Newbie
 
Registered: Nov 2005
Posts: 1

Rep: Reputation: 0
Lightbulb

allright, the answer was simple:
instead of typing
echo 'something' > pairwise.gp
I have to type
echo 'something' > /path/to/pairwise.gp

SOLVED
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute bash script inside PHP creatorrr Programming 11 11-21-2007 04:32 PM
remote execute a bash script vmware Linux - Enterprise 3 09-07-2006 03:01 PM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 01:34 AM
fastest way to execute another bash script ?? michael_util Programming 3 08-23-2004 10:04 AM
Trying to execute bash script upon login?? mr-d-2003 Linux - Newbie 4 10-30-2003 03:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration