Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Abishek Goda
Hi,
 I was writing a few lines of script to change the  *pwd* of my BASH to my
 *project workspace* whenever i call it (because its a long path)

 #!/bin/bash
 DIRECTORY=/home/varrun/Desktop/TODO/Final_yr_project
 if [ -d $DIRECTORY ]; then
        echo exists
        cd  $DIRECTORY
 else
        echo project directory either wrong or doesnt exist
 fi

 When i run it, the directory of my terminal does *not* change i guess
 because a child process cannot pass arguments to a parent process.
 Is there any other way i can do this?

Well, I think it should not change the directory of the calling
terminal, but within the script the directory will change. Try echoing
$PWD after the cd command.

Abishek
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Varrun Ramani
2009/12/29 Shakthi Kannan shakthim...@gmail.com


 Try:

  $ source your-script.sh


Yes, that works, but thats as bad as typing a cd command everytime. I want
to run a short command like pc (for project change :) ) by copying it to
/sbin


2009/12/29 Abishek Goda goda.abis...@gmail.com


 Well, I think it should not change the directory of the calling
 terminal, but within the script the directory will change. Try echoing
 $PWD after the cd command.

 Yes, i know that. But i want a solution wherein the pwd of parent process
changes

-- 
Thanks  Regards
Varrun Ramani
Amrita University '10
Web: varrunr.wordpress.com
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Shakthi Kannan
Hi,

--- On Tue, Dec 29, 2009 at 9:44 PM, Varrun Ramani
darthsit...@gmail.com wrote:
| Yes, that works, but thats as bad as typing a cd command everytime.
\--

Everytime? These are new requirements :) You had only asked as to how
to cd to a directory from a script.

---
| I want
| to run a short command like pc (for project change :) ) by copying it to
| /sbin
\--

This should have been your actual question. It always helps to know
what you are trying to accomplish. Anyways, you could export the PC
command in your ~/.bashrc:

  export PC='cd /path/to/project/directory'

Source your ~/.bashrc once:

  $ source ~/.bashrc

and then use:

  $ $PC

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Bharathi Subramanian
Varrun Ramani said:

Instead of script, try to use alias command.

alias pc='cd /home/varrun/Desktop/todo/project'

OR use CDPATH

Bye :)
-- 
Bharathi S
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Raja Subramanian
On Tue, Dec 29, 2009 at 9:44 PM, Varrun Ramani darthsit...@gmail.com wrote:
 Yes, that works, but thats as bad as typing a cd command everytime. I want
 to run a short command like pc (for project change :) ) by copying it to
 /sbin

If you copy your binaries or scripts into /sbin, you will break your
system in weired and wonderful ways.

Please read up on Linux Filesystem Hierarchy Standard to
learn the directory layout and consider putting your scripts in
/usr/local/bin/.

- Raja
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Gourav Shah
   export PC='cd /path/to/project/directory'

 Source your ~/.bashrc once:

  $ source ~/.bashrc

 and then use:

  $ $PC


this should work. however there is a better option  than exporting command
line as a environment variable = specify an  alias in bashrc


http://linux.about.com/library/glossary/bldef_alias.htm
http://www.linux.org/lessons/beginner/l6/lesson6a.html

Varrun, this  is exactly what you should be doing. There is no need to
write a bash script to alias a command.


thanks
gourav
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-29 Thread Varrun Ramani
2009/12/29 Shakthi Kannan shakthim...@gmail.com


 Everytime? These are new requirements :) You had only asked as to how
 to cd to a directory from a script.


Sorry about that.



  export PC='cd /path/to/project/directory'


Yeah, that works. Thanks.

2009/12/29 Bharathi Subramanian sbhara...@midascomm.com


 Instead of script, try to use alias command.

 alias pc='cd /home/varrun/Desktop/todo/project'


Yea, that works but only for the current shell. Adding it to the bashrc file
should work universally though as Gourav pointed out.

2009/12/30 Raja Subramanian rajasuper...@gmail.com


 Please read up on Linux Filesystem Hierarchy Standard to
 learn the directory layout and consider putting your scripts in
 /usr/local/bin/.


I did not know that there were Filesystem standards. Will read up on it
-- 
Thanks  Regards
Varrun Ramani
Amrita University '10
Web: varrunr.wordpress.com
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


[Ilugc] shell script - changing directory

2009-12-28 Thread Varrun Ramani
Hi

I was writing a few lines of script to change the  *pwd* of my BASH to my
*project workspace* whenever i call it (because its a long path)

#!/bin/bash
DIRECTORY=/home/varrun/Desktop/TODO/Final_yr_project
if [ -d $DIRECTORY ]; then
echo exists
cd  $DIRECTORY
else
echo project directory either wrong or doesnt exist
fi

When i run it, the directory of my terminal does *not* change i guess
because a child process cannot pass arguments to a parent process.
Is there any other way i can do this?

Also, why does it show an error when i change
DIRECTORY=~/Desktop/TODO/Final_yr_project

-- 
Thanks  Regards
Varrun Ramani
Amrita University '10
Web: varrunr.wordpress.com
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-28 Thread Roshan Mathews
On Tue, Dec 29, 2009 at 1:05 PM, Varrun Ramani darthsit...@gmail.com wrote:
 When i run it, the directory of my terminal does *not* change i guess
 because a child process cannot pass arguments to a parent process.
 Is there any other way i can do this?

Instead of running it as
$ ./script
or
$ sh ./script
try
$ source ./script
or
$ . ./script

This might be a hack, so look around for better solutions.

 Also, why does it show an error when i change
 DIRECTORY=~/Desktop/TODO/Final_yr_project

Maybe ~ isn't expanded in scripts?

-- 
Roshan Mathews
http://teamtalk.im
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] shell script - changing directory

2009-12-28 Thread Shakthi Kannan
Hi,

--- On Tue, Dec 29, 2009 at 1:05 PM, Varrun Ramani
darthsit...@gmail.com wrote:
| When i run it, the directory of my terminal does *not* change i guess
| because a child process cannot pass arguments to a parent process.
\--

Try:

  $ source your-script.sh

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc