LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-29-2010, 10:44 PM   #1
ahtoot
LQ Newbie
 
Registered: Jun 2005
Posts: 22

Rep: Reputation: 1
Appending to PROMPT_COMMAND


I have the following as my $PROMPT_COMMAND in .bashrc:

Code:
PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
 MYPWD="${PWD/#$HOME/~}"
 [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
 echo -n -e "\033k$MYPWD\033\\"
fi
'
I am trying to append items to my PROMPT_COMMAND in another script/on command line. If I do the following:

Code:
export PROMPT_COMMAND="$PROMPT_COMMAND && ls"
bash has a syntax error and complains of unexpected token near &&.
But if I change the following in .bashrc

Code:
PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
 MYPWD="${PWD/#$HOME/~}"
 [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
 echo -n -e "\033k$MYPWD\033\\"
fi && ls
'
I get no error.

I've echoed the value of $PROMPT_COMMAND in both cases and their output is exactly the same.


Any tips? Thanks.
 
Old 09-29-2010, 11:08 PM   #2
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
It probably has to do with the fact that you already have quotes inside the original prompt command.
 
Old 09-29-2010, 11:33 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am curious what you expect to happen?

If you did the following on the command line:
Code:
PROMPT_COMMAND="$PROMPT_COMMAND && ls"
And now perform an echo, all that has happened is '&& ls' gets appended to the string.

The questions then becomes, what is processing $PROMPT_COMMAND?
 
Old 09-30-2010, 01:08 AM   #4
ahtoot
LQ Newbie
 
Registered: Jun 2005
Posts: 22

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by grail View Post
I am curious what you expect to happen?

If you did the following on the command line:
Code:
PROMPT_COMMAND="$PROMPT_COMMAND && ls"
And now perform an echo, all that has happened is '&& ls' gets appended to the string.

The questions then becomes, what is processing $PROMPT_COMMAND?
bash is processing $PROMPT_COMMAND
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html


I've solved it, I had to put the last quote on the same line as the last fi

Code:
PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
 MYPWD="${PWD/#$HOME/~}"
 [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
 echo -n -e "\033k$MYPWD\033\\"
fi'

Now if someone can tell me why the previous version didn't work..

Code:
PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
 MYPWD="${PWD/#$HOME/~}"
 [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
 echo -n -e "\033k$MYPWD\033\\"
fi
'
Edit: Maybe because && can't start on a newline?

Last edited by ahtoot; 09-30-2010 at 01:10 AM.
 
Old 09-30-2010, 01:12 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Because the fi command needs to be terminated -- by a ; or by a newline.
 
  


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
Problems appending avis Blue1K Linux - General 3 06-27-2009 12:32 PM
Appending the files dina3e Programming 4 10-15-2008 07:03 PM
Appending to a log file (C++) itz2000 Programming 4 10-27-2006 09:57 AM
appending a file circuit_girl Programming 8 10-01-2006 11:00 AM
C character appending Chrax Programming 6 12-23-2004 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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