LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2007, 11:01 AM   #1
ovince
Member
 
Registered: Mar 2007
Posts: 77

Rep: Reputation: 15
function in .bashrc


Hi

I would like to put a function into .bashrc file that would
open a new Konsole and cd into the result of the pwd command. Something like:

pwdinnk() {
p=`echo pwd`
echo $p
`dcop $KONSOLE_DCOP newSession`
`cd $p`
}

This does not work. In details:

1. The echo $p part does not give me back the current path. What is wrong here?

2. this part `dcop $KONSOLE_DCOP newSession` works OK. It opens a new Konsole just as I want

3. The `cd $p` I wrote ad hoc just to present the idea. What would be the proper syntax here?

Could somebody help me on this?

thanks
oliver
 
Old 04-25-2007, 11:27 AM   #2
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
Code:
p=`echo pwd`
means p="pwd". Try this:

Code:
p=`pwd`
 
Old 04-25-2007, 11:35 AM   #3
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
thanks reverse


I tried this two options and the $p is properly initialised, the newKonsole is opened BUT changing directory part does not work in nither of them

pwdinnk() {
p=`pwd`
echo $p
`dcop $KONSOLE_DCOP newSession`
cd $p
}

pwdinnk() {
p=`pwd`
echo $p
`dcop $KONSOLE_DCOP newSession`
`cd $p`
}

o.
 
Old 04-25-2007, 11:38 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
1. $PWD or pwd
2. okay. Don't know why you want it in backticks, though.
3. Again, why backticks? Moreover, though, the shell running in your Konsole session will not execute this command.

It will, if it is bash, try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash, which will try to execute .bashrc, which will invoke 'dcop $KONSOLE_DCOP newSession' which will spawn a new Konsole session running bash....

--- rod.

Last edited by theNbomr; 04-25-2007 at 11:40 AM.
 
Old 04-25-2007, 12:04 PM   #5
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by ovince
Hi

I would like to put a function into .bashrc file that would
open a new Konsole and cd into the result of the pwd command.

Why do you want to cd into the directory you are already in?
Quote:
Something like:

pwdinnk() {
p=`echo pwd`
echo $p
`dcop $KONSOLE_DCOP newSession`
`cd $p`
}

This does not work. In details:

1. The echo $p part does not give me back the current path. What is wrong here?

Code:
p=$PWD
Quote:
2. this part `dcop $KONSOLE_DCOP newSession` works OK. It opens a new Konsole just as I want

It does? Do you really want to execute the output of the dcop command?

(I don't know what dcop does, so my comments here may or may not be relevant)
Quote:
3. The `cd $p` I wrote ad hoc just to present the idea. What would be the proper syntax here?

If you want to execute a command in a konsole, it needs to be in a file that is sourced within that konsole, not something that is executed afterwards.


Last edited by cfaj; 04-25-2007 at 12:25 PM.
 
Old 04-25-2007, 12:15 PM   #6
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
cfaj, I need two Konsole with the same dir sometimes

Have an idea how to do accomplishe this?
 
Old 04-25-2007, 12:26 PM   #7
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by ovince
cfaj, I need two Konsole with the same dir sometimes

Have an idea how to do accomplishe this?

Why do they open in a different directory?

If they do, it's because something is telling them to (e.g., .bashrc). Fix that.

 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what are the Hexadecimal function and ASCII function in Perl Bassam Programming 1 06-03-2004 01:44 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Is the wait function is the same as the sleep function ? Linh Programming 3 04-28-2004 12:39 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM
alias or function in .bashrc, which sends command to background ngomong Linux - General 1 04-23-2002 09:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 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