[solved][bash] PS1 wrapping problem...
Hello I have my ps1 set to
# Prompt
BGREEN='\[\033[1;32m\]'
GREEN='\[\033[0;32m\]'
BRED='\[\033[1;31m\]'
RED='\[\033[0;31m\]'
BBLUE='\[\033[1;34m\]'
BLUE='\[\033[0;34m\]'
NORMAL='\[\033[00m\]'
if [ "$TERM" = "linux" ]; then
PS1="${NORMAL}[\u${BLUE}@\h ${BGREEN}\W${NORMAL}]\$ "
else
PS1="\e]2;\u@\H:\w\a${NORMAL}[\u${BLUE}@\h ${BGREEN}\W${NORMAL}]$ "
fi
However when my prompt displays [pyther@tux world.pyther.net]$ (color) I can only type 3 characters and then it wraps. Please see the screenshot...
Using a regular prompt (source /etc/profile) works like a charm. Any help would be great!
Last edited by pyther (2008-10-15 03:06:48)
Daenyth wrote:Didn't I just answer this question in another thread? You need to escape the colors codes with \[ \] so that bash knows that they are non-printing characters, otherwise they will be counted in the prompt length.
You're probably confusing this thread with mine a few days ago about using colors in PS1 in bash. ( http://bbs.archlinux.org/viewtopic.php? … 03#p432903 )
This issue is very similar indeed
Last edited by Dieter@be (2008-10-15 19:41:56)
Similar Messages
-
[SOLVED] Bash initial directory problem
Over the last couple of days, whenever I've opened any X virtual terminal (it doesn't do it when I ctrtl-alt-fX), it opened in a directory within my home directory, (namely the one I use for various programming projects), instead of the home directory. I thought that maybe if I removed that directory it might solve the problem, so I did, but apparently it didn't fix it, because now it outputs this:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
It outputs a subtly different message (chdir instead of shell-init) when I cd into a different directlry. I looked through my .bashrc, .bash_profile and .Xresources and none of them had anything relating to directories.
Does anyone know how I could fix this?
Last edited by alexanderthegre (2012-09-30 22:36:42)Did you launch X in that directory?
sudo ls -dl /proc/$(pgrep Xorg)/cwd
Or maybe the program you use to launch the terminal (WM, xbindkeys, etc)? -
(SOLVED) bash script header problem
When i run this piece of code from the command line it works properly, but when i try and run it from a script it doesn't.
It's supposed to be the beginning of a header
printf "%*s\n" "$((COLUMNS))" " " | tr " " "=" ; printf "%*s\n" $((COLUMNS/2)) " Database " ; printf "%*s\n" $((COLUMNS)) " " | tr " " "="
Any help would be appreciated, thanks
Last edited by unilx (2012-04-23 23:58:53)COLUMNS is not defined in a normal script.
Now to find a solution ...
Edit: does "sourcing" the script work from an interactive session?
e.g.
~$ ./test.sh
./test.sh: line 2: 0: command not found
$ . test.sh
bash: 89: command not found
where test.sh has only
#!/bin/bash
$((COLUMNS))
Edit2:
try
WIDTH=`stty size | cut -d" " -f2`
then use $WIDTH instead of $((COLUMNS))
Last edited by Trilby (2012-04-23 23:16:22) -
[SOLVED]How to make a multiline PS1 wrap properly
Hello,
Im am having a problem with my PS1 wrapping improperly when a command is loger than one line.
Here is my PS1:
PS1='$(tput bold)\e[0;34m┌─[\e[m$(tput sgr0)\@$(tput bold)\e[0;34m]─[\e[m$(tput sgr0)\u$(tput bold)\e[0;34m]─[\e[m\W\e[0;34m]\n└─[\e[m$(tput sgr0)\$$(tput bold)\e[0;34m]─>\e[m$(tput sgr0) '
Here's what happens:
┌─[07:00 PM]─[eric]─[~]
ng_line pacman -S a_really_really_really_really_lo
Here's what it should look like:
┌─[07:00 PM]─[eric]─[~]
└─[$]─> pacman -S a_really_really_really_really_long_line
anyone who knows how to fix this please help.
Last edited by TheCash (2010-07-19 14:03:05)I'm glad you got it working! Please prepend "[Solved]" to the thread title by editing the first post.
The third time you try to use $white, you have w$hite typed instead Also, if it's easier for you, you can put the \[ and \] in the variable, if I recall correctly.
Last edited by jac (2010-07-19 14:00:32) -
Any way of finding out how Apple will solve the Aperture / ACR problem?
Has anyone out there gotten any comments from Apple support or other people "in the know" about how Apple is going to solve the Aperture / ACR problem, and any potential time frame?
Of course, Apple is going to work on problems with its own RAW conversion; that goes without saying. But does anyone have any knowledge of whether Apple is going to open up the ability for Apple to send RAW, unconverted images to Photoshop, so that ACR can handle them?
I think knowing this now is pretty crucial. I am willing to live with the pain Aperture is going to impose on my workflow, in exchange for the file organization benefits it provides, IF I know that I'll be able to use Aperture with ACR soon (near term). But if Apple is going to just tinker with the RAW converter, and not attempt to send RAW files to ACR, then as someone else posted in another topic, this could be a long wait, and other companies have taken years to hone their RAW converters.
This is kind of my last-ditch effort to keep Aperture around, and build my workflow around it. If I know that within a month or two at the most, I'll be able to be using ACR directly when editing new versions, then I'll absorb the pain until then. But if I am looking at waiting six months for it (several man years), or riding out the process of Apple trying to get their own converter fixed, then as much as I don't want to, Aperture is going to get returned or hit eBay.
Does anyone have any idea on this? I've held up my projects for the past week trying to reorganize my workflow to work with Aperture, and I've got to pound the gavel, make a decision, and pursue a direction. Knowing what direction Apple is going to take with this makes all the difference in the world in what I do.
Thanks in advance for any info you can pass on.
Brad
Powerbook G4-1.33GHz-17" / Powermac G4-1.4GHz Mac OS X (10.4.2) PB: 1GB RAM, Radeon 9600-64MB / PM: 1.25GB RAM, Radeon 9000Pro-128MBThis "Open External Editor from Master NEF", versus open from a dynamicaly created version is, I have decided, crucial.
I am getting less clumsy with the interface, but I simply can not get all white balance, and noise reduction done on my best available light shots.
ACR in CS2, and a subsequent "Neat Image" scrubbing is excellent for this.
The automatic association within a stack, of the resulting flattened file would be a big difference. I agree a formal statement from Apple would make me more inclined to really commit to Aperture for all my work.
Going one step further, it would be nice to keep the layers on the round-trip Master file, even if you would work with a dynamicaly created version of the returned "master" within a stack. It would occupy more disk space, but would do so only for those images where the user has made a quality decision.
Michael
Powermac G5 dual 2GHZ, 2.5GB - 2x20in Mac OS X (10.3.4) -
HT1212 How to solve the forgotten passcode problem
If I never connect my iPhone5 to iTunes, didnt turn on the iCloud, and did not backup my phone before, how can i solve the forgotten passcode problem without erasing the data?
Read the article that brought you here
http://support.apple.com/kb/ht1212
There is nothing you can do other than that and you will lose your data if you have never backed up -
Solving u0091Out of Memoryu0092 problem u0096 Using JNLP
Hi all,
I am just following the below mentioned blog /people/keerti.nayak/blog/2007/03/05/solving-145out-of-memory146-problem-150-using-jnlp
I got stuck @ step 2.
can anyone tell me... whats the exact path of the launcher file.
Regards
BiplabHi,
If you place the Mouse on the Integration Repository,
You will be able to see the path on the bottom left side of the screen, which is marked as Red in the Blog
In my case the path is----http://sxddev:50000/rep/start/repository.jnlp
Regards
Seshagiri -
Does upgrading from Premiere Elements 12 to 13 solve the Organizer thumbnail problem?
Thumbnails do not show up after importing clips into Premiere Elements 12 Organizer. I've tried right clicking on a clip and telling it to recreate the thumbnail but it doesn't work. I've tried refreshing and repairing the catalog. I've even started a new catalog and reimported the files. The system says it's creating thumbnails but they still do not show up. Does upgrading from Premiere Elements 12 to 13 solve the Organizer thumbnail problem?
listiak
That is one of those questions best answered by evaluating Elements Organizer13 with your specific files in your specific computer environment.
Each of the Elements Organizer versions often appears to carry along its own baggage.
One of the things that came up about Elements Organizer 13 thumbnails recently was a problem with files with MPEG2
video compression. The Adobe word on this was that this is only an Elements Organizer 13 tryout issue...supposed not to exist
in the purchased version.
ATR -
[SOLVED] help converting bash PS1 prompt to zsh PS1 prompt
I guess they don't use the same syntax because simply copying it over to my zshrc does not work... it literally changes my prompt to the exact string of backlslashes etc
If anyone can help me convert the following to zsh syntax I would be much in their debt:
PS1="$TITLEBAR [\[\e[37m\]\u\[\e[31m\]@\[\e[37m\]\h\[\e[0m\]:\[\e[33m\]\w\[\e[0m\]] \$ ${NONE}"
full bit copied from some thread in this forums... it had served me well
bash_prompt() {
case $TERM in
xterm*|rxvt*)
local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
local TITLEBAR=""
esac
local NONE="\[\033[0m\]" # unsets color to term's fg color
# regular colors
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
local G="\[\033[0;32m\]" # green
local Y="\[\033[0;33m\]" # yellow
local B="\[\033[0;34m\]" # blue
local M="\[\033[0;35m\]" # magenta
local C="\[\033[0;36m\]" # cyan
local O="\[\033[0;37m\]" # orange
local W="\[\033[0;38m\]" # white
# emphasized (bolded) colors
local EMK="\[\033[1;30m\]"
local EMR="\[\033[1;31m\]"
local EMG="\[\033[1;32m\]"
local EMY="\[\033[1;33m\]"
local EMB="\[\033[1;34m\]"
local EMM="\[\033[1;35m\]"
local EMC="\[\033[1;36m\]"
local EMW="\[\033[1;37m\]"
# background colors
local BGK="\[\033[40m\]"
local BGR="\[\033[41m\]"
local BGG="\[\033[42m\]"
local BGY="\[\033[43m\]"
local BGB="\[\033[44m\]"
local BGM="\[\033[45m\]"
local BGC="\[\033[46m\]"
local BGW="\[\033[47m\]"
local UC=$W # user's color
[ $UID -eq "0" ] && UC=$R # root's color
PS1="$TITLEBAR [\[\e[37m\]\u\[\e[31m\]@\[\e[37m\]\h\[\e[0m\]:\[\e[33m\]\w\[\e[0m\]] \$ ${NONE}"
#PS1="$TITLEBAR ${EMK}[${UC}\u${EMK}@${UC}\h ${EMB}\${NEW_PWD}${EMK}]${UC}\\$ ${NONE}"
# without colors: PS1="[\u@\h \${NEW_PWD}]\\$ "
# extra backslash in front of \$ to make bash colorize the prompt
PROMPT_COMMAND=bash_prompt_command
bash_prompt
unset bash_prompt
Last edited by ugkbunb (2009-09-04 17:56:55)If it spits out errors you should read them.. They generally tell you what the script expects. I saved your prompt in test and passed it to the script:
$ perl tozsh.pl test && rm test
# Converted to zsh prompt theme by bash2zshprompt, written by <[email protected]>
[%{$fg[white]%}%n%{$fg[red]%}@%{$fg[white]%}%m%{$reset_color%}:%{$fg[yellow]%}%~%{$reset_color%}] \ -
[Solved] buggy PS1 in bash
Hi, what I'm trying to achieve is a bash prompt that is pretty default (user@host current-directory) but, the current directory must be shown in red if the last command was unsucessful, green otherwise.
This is in my .bashrc
if [ $(tput colors) -gt 0 ] ; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
RST=$(tput op)
fi
bash_prompt_command() {
last_exit=$?
exit_to_color=$(exit_to_color $last_exit)
export PROMPT_COMMAND=bash_prompt_command
exit_to_color() {
[ $1 == 0 ] && echo $GREEN || echo $RED
PS1="\u@\h \$exit_to_color\W\[$RST\] \$"
The color thingie works, but sometimes \W doesn't show anything at all. example:
dieter@dieter-mbp ~ $pwd
/home/dieter
dieter@dieter-mbp ~ $cd .reference/
dieter@dieter-mbp .reference $cd
dieter@dieter-mbp ~ $cd workspaces/
dieter@dieter-mbp $pwd
/home/dieter/workspaces
dieter@dieter-mbp $
Also, sometimes I see 'leftovers' from the previous command on my prompt, if I use bash history functions and I can't erase them.
dieter@dieter-mbp ~ $svn diff workspaces/eclipse/tools/scripts/cdnbench.php >/dev/null
dieter@dieter-mbp ~ $svn d #<--- what I did here is press up arrow (shows previous command perfectly), and then down arrow (doesn't clean up everything)
Note that it's just a visual artifact, not a functional one:
dieter@dieter-mbp ~ $svn diff workspaces/eclipse/tools/scripts/cdnbench.php >/dev/null
dieter@dieter-mbp ~ $svn decho ok
ok
dieter@dieter-mbp ~ $ # if i press up arrow at this point, it shows the previous command 'echo ok', pressing down works fine too
Any ideas?
Last edited by Dieter@be (2008-10-13 18:36:44)Daenyth wrote:You need to escape color codes with \[ \] or it will count them as printing characters, hence the visual offset.
Thanks a lot !
Changed it to
PS1="\u@\h \[\$exit_to_color\]\W\[$RST\] \$"
works like a charm now -
How to solve text wrapping problem in grid
I have create a simple ui with grid and contains a long paragraph text. However the text will not break line to another paragraph and expand the UI width.
BView.xaml
<UserControl x:Class="SimpleUI.Views.BView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resources="clr-namespace:SimpleUI.Properties"
xmlns:view="clr-namespace:SimpleUI.Views"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<GroupBox Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Header="{x:Static resources:Resources.Course}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width="2" />
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width="2" />
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width="2" />
</Grid.ColumnDefinitions>
<UniformGrid Grid.Column="0" Grid.Row="1" Columns="2" Grid.ColumnSpan="6" HorizontalAlignment="Center" VerticalAlignment="Center">
<RadioButton Margin="0, 0, 10, 0" GroupName="ClassType" Content="{x:Static resources:Resources.ClassA}" />
<RadioButton Margin="0, 0, 10, 0" GroupName="ClassType" Content="{x:Static resources:Resources.ClassB}" />
</UniformGrid>
<Border Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="6" BorderThickness="1" Padding="9" BorderBrush="LightGray">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="10" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="2" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".3*" />
<ColumnDefinition Width="10"/>
<ColumnDefinition Width=".25*" />
<ColumnDefinition Width="10"/>
<ColumnDefinition Width=".25*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static resources:Resources.MaterialA}" />
<TextBox Grid.Column="2" Grid.Row="0" Width="120" />
<ComboBox Grid.Column="4" Grid.Row="0" Width="120"/>
<TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static resources:Resources.MaterialB}" />
<TextBox Grid.Column="2" Grid.Row="2" Width="120" />
<ComboBox Grid.Column="4" Grid.Row="2" Width="120" />
<TextBlock Grid.Column="0" Grid.Row="4" Text="{x:Static resources:Resources.MaterialC}" />
<TextBox Grid.Column="2" Grid.Row="4" Width="120" />
<ComboBox Grid.Column="4" Grid.Row="4" Width="120" />
</Grid>
</Border>
<view:MessageView Grid.Column="0" Grid.Row="5" />
</Grid>
</GroupBox>
</Grid>
</UserControl>
MessageView.xaml
<UserControl x:Class="SimpleUI.Views.MessageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resources="clr-namespace:SimpleUI.Properties"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{x:Static resources:Resources.Error}" TextTrimming="None" FontWeight="UltraBold" />
<TextBlock Grid.Row="2" Text="{x:Static resources:Resources.ErrorDescription}" TextAlignment="Justify" TextWrapping="Wrap" VerticalAlignment="Center" />
</Grid>
</UserControl>
MainWindow.xaml
<UserControl x:Class="SimpleUI.Views.MessageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resources="clr-namespace:SimpleUI.Properties"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{x:Static resources:Resources.Error}" TextTrimming="None" FontWeight="UltraBold" />
<TextBlock Grid.Row="2" Text="{x:Static resources:Resources.ErrorDescription}" TextAlignment="Justify" TextWrapping="Wrap" VerticalAlignment="Center" />
</Grid>
</UserControl>
Target Result
Download Sample ProjectHere is updated code for BView.xaml. It will fix the problem
<UserControl x:Class="SimpleUI.Views.BView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resources="clr-namespace:SimpleUI.Properties"
xmlns:view="clr-namespace:SimpleUI.Views">
<GroupBox Header="{x:Static resources:Resources.Course}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<UniformGrid Grid.Row="1"
Columns="2"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<RadioButton Margin="0, 0, 10, 0"
GroupName="ClassType"
Content="{x:Static resources:Resources.ClassA}" />
<RadioButton Margin="0, 0, 10, 0"
GroupName="ClassType"
Content="{x:Static resources:Resources.ClassB}" />
</UniformGrid>
<Border Grid.Row="3"
BorderThickness="1"
Padding="9"
BorderBrush="LightGray">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="2" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Grid.Row="0"
Text="{x:Static resources:Resources.MaterialA}" />
<TextBox Grid.Column="2"
Grid.Row="0"
Width="120" />
<ComboBox Grid.Column="4"
Grid.Row="0"
Width="120" />
<TextBlock Grid.Column="0"
Grid.Row="2"
Text="{x:Static resources:Resources.MaterialB}" />
<TextBox Grid.Column="2"
Grid.Row="2"
Width="120" />
<ComboBox Grid.Column="4"
Grid.Row="2"
Width="120" />
<TextBlock Grid.Column="0"
Grid.Row="4"
Text="{x:Static resources:Resources.MaterialC}" />
<TextBox Grid.Column="2"
Grid.Row="4"
Width="120" />
<ComboBox Grid.Column="4"
Grid.Row="4"
Width="120" />
</Grid>
</Border>
<view:MessageView Grid.Row="5" />
</Grid>
</GroupBox>
</UserControl> -
[SOLVED] bash expansion problem
I have a partial file name, suppose file=night
I want to find files having similar names with *$file*
since given file names can contain spaces, the search string should be '*$file*'
so I do q=\' and string=$q*${file}*$q
echo $string produces '*night*'
but when I do
find <location> -iname ${string} , string expands to ''\''*night*'\''' and I get no search output.
If string is assigned like string='*night*', it works; but if string="'*night*'" it doesn't (although echo produces expected output).
I need the single quote encapsulation because there maybe spaces in the file name.
EDIT: Even "find <location> -iname $(echo "$sstring")" doesn't work.
Basically, when string doesn't have quotes embedded in it, it works. Otherwise not.
I'm looking for a solution..
Here's the script and the output if you need.
Thanks.
#!/bin/bash -x
export mlibrary='/media/Entertainment/songs/'
find_and_play() {
echo -n 'Track name: '
read track
q=\'
sstring=$q*"$track"*$q
echo ${sstring}
IFS='
sfiles=(`find ${mlibrary} -depth -iname "$sstring"`)
#echo ${sfiles[0]}
for t in `seq 1 ${#sfiles[@]}`; do
echo "$t==> ${sfiles[$t]}"
done
exit 0
find_and_play
+ export mlibrary=/media/Entertainment/songs/
+ mlibrary=/media/Entertainment/songs/
+ find_and_play
+ echo -n 'Track name: '
Track name: + read track
night
+ q=''\'''
+ sstring=''\''*night*'\'''
+ echo ''\''*night*'\'''
'*night*'
+ IFS='
+ sfiles=(`find ${mlibrary} -depth -iname "$sstring"`)
++ find /media/Entertainment/songs/ -depth -iname ''\''*night*'\'''
+ echo
++ seq 1 0
+ exit 0
Last edited by debdj (2012-06-14 11:20:21)debdj wrote:@falconindy I guess the -d option to read defines delimiter and -a is array? Its not documented in the man page.
It's in the bash man page:
read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t time‐
out] [-u fd] [name ...]
One line is read from the standard input, or from the file descriptor fd supplied
as an argument to the -u option, and the first word is assigned to the first name,
the second word to the second name, and so on, with leftover words and their inter‐
vening separators assigned to the last name. If there are fewer words read from
the input stream than names, the remaining names are assigned empty values. The
characters in IFS are used to split the line into words. The backslash character
(\) may be used to remove any special meaning for the next character read and for
line continuation. Options, if supplied, have the following meanings:
-a aname
The words are assigned to sequential indices of the array variable aname,
starting at 0. aname is unset before any new values are assigned. Other
name arguments are ignored.
-d delim
The first character of delim is used to terminate the input line, rather
than newline. -
[SOLVED] bash: sleep not a builtin?
hello,
i have a few scripts running in endless loops, using the sleep command.
this causes constant i/o - not much, but nevertheless.
i went to investigate this further and found that on (archlinux') bash, sleep is not a builtin by default, nor can it be enabled with the "enable" command.
this seems less than optimal to me.
i can't find any packages that would remedy that, either.
how can i solve this?
thoughts, most preferable first:
1) there is some other bash-builtin i've missed, or some workaround that has the same effect.
2) copy the sleep command to /dev/shm/bin and add that to my path. feels hackish, but why not?
3) recompile bash (i read the debian version has sleep as a builtin)?
4) change to another (preferably bash-compatible) shell?
cheers,
o.
Last edited by ondoho (2014-01-06 21:29:31)dzen for system resource monitoring was something I wanted to bring up, but I wasn't sure what purpose of your script, so I didn't bring it up.
About two or three years ago, I switched to dzen from Conky for system resource monitoring. Like many people, suggestions, and examples on the Internet, I used Bash to write the script [1] to feed the data into dzen. It wasn't long before I realize the script had eaten up 100MB memory.
It was the time I first noticed the issue with Bash scripting. Yes, there are times for cron and should be used with cron, but for this situation and type of case, you can't. I did try to isolate the problem by removing some monitoring components, but, IIRC, the memory was still being eaten.
The 3,000 iterations in my previous might sound a lot at first glance, but the point isn't the iterations but how many invocations of external commands. And 3000 calls of external externally actually ain't a lot, even for one-off or once in long time scripts. That's where the problem is linked from what I see, although I still don't know what the actually cause is.
After I failed to find the leak--or is there really one? I ported the Bash script to C [2]. It's much efficient.
Note that for both code, they are updating as fast as 0.2 seconds depending on what system resources. I found 1 second is too long, especially when you are pressing volume up key, even it's roughly okay for system clock.
I'd advise everyone to take a close look at "TIME+" in top/htop, you might find some programs that you don't expect to use that much time and some the other way around.
By the way, when I said "little obsessive" about myself, I only meant PS1 in loadable C extension is obsessive--who even does like `enable -f vimps1 vimps1` for your PS1? But other parts don't count, because those are clearly wasting if the code is executed a lot and you don't deal with.
[1]: https://github.com/livibetter/dotfiles/ … /status.sh
[2]: https://github.com/livibetter/dotfiles/ … n/status.c -
[SOLVED]Bash prompt colors different in console as opposed in terminal
Hi
EDIT: I have solved the problem by copying /etc/skel/.bash_profile to my home directory.
Today i updated the system and the bash prompt is fine in my terminal (KDE Konsole or in Xterm) but not in consoles. For normal user (blue colors) i use this settings in the $HOME/.bashrc file:
PS1='[\e[0;36m\u\e[0m@\e[0;36m\h\e[0m]─[\e[0;33m\w\e[0m]\n└─\$ '
For root (red color) /root/.bashrc:
PS1='[\e[1;31m\u\e[0m@\e[1;31m\h\e[0m]─[\e[0;33m\w\e[0m]\n└─\$ '
Now, if i login in console as a normal user it doesn't display blue color but red as if i was root user. Like i said in xterm or KDE Konsole it looks just fine. The case is that consoles don't use my .bashrc file and use instead /etc/bash.bashrc file: Here is my /etc/bash.bashrc file:
# /etc/bash.bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
#PS1='[\u@\h \W]\$ '
PS1='[\e[1;31m\u\e[0m@\e[1;31m\h\e[0m]─[\e[0;33m\w\e[0m]\n└─\$ '
PS2='> '
PS3='> '
PS4='+ '
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
screen)
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
esac
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
export EDITOR=/usr/bin/nano
Here is my today's update:
[2012-07-06 08:54] upgraded linux-api-headers (3.3.8-1 -> 3.4.4-1)
[2012-07-06 08:54] warning: /etc/locale.gen installed as /etc/locale.gen.pacnew
[2012-07-06 08:54] Generating locales...
[2012-07-06 08:54] en_GB.UTF-8... done
[2012-07-06 08:54] en_GB.ISO-8859-1... done
[2012-07-06 08:54] Generation complete.
[2012-07-06 08:54] upgraded glibc (2.15-12 -> 2.16.0-1)
[2012-07-06 08:54] upgraded binutils (2.22-7 -> 2.22-8)
[2012-07-06 08:54] upgraded dbus-core (1.6.0-5 -> 1.6.2-2)
[2012-07-06 08:54] upgraded dbus (1.6.0-1 -> 1.6.2-1)
[2012-07-06 08:54] upgraded device-mapper (2.02.96-2 -> 2.02.96-3)
[2012-07-06 08:54] upgraded gcc-libs (4.7.1-3 -> 4.7.1-4)
[2012-07-06 08:54] upgraded gcc (4.7.1-3 -> 4.7.1-4)
[2012-07-06 08:54] upgraded grep (2.12-1 -> 2.13-1)
[2012-07-06 08:54] upgraded initscripts (2012.06.3-1 -> 2012.06.3-2)
[2012-07-06 08:54] upgraded libpurple (2.10.4-2 -> 2.10.5-1)
[2012-07-06 08:54] upgraded libusb-compat (0.1.4-1 -> 0.1.4-2)
[2012-07-06 08:54] upgraded lvm2 (2.02.96-2 -> 2.02.96-3)
[2012-07-06 08:54] upgraded mpfr (3.1.0.p10-1 -> 3.1.1-1)
Is it a problem in yesterday's pam upgrade? Yesterday i have moved /etc/pam.d/login.pacnew to /etc/pam.d/login. I didn't backup the old file. My bad. Weird thing is also this that today my KDE session crashed (for the first time) when i have used dd to burn image on my USB.
Last edited by Shark (2012-07-06 08:40:31)Procyon wrote:What you want is [ -n "$SSH_CONNECTION" ] (variable is set/nonzero length) or the opposite [ -z "$SSH_CONNECTION" ] (variable is not set/zero length)
Thanks-- that got it. I was missing the quotes, so it was expanding at the spaces rather than interpreting the entire thing as a string. -
JEdtiorPane/HTMLEditorKit word wrapping problems
Hi,
I have a JFrame component that has a splitPane, on the left side is a JTree and the right side has a JEditorPane that has it's content updated with HTML using a method to generate the HTML via the setText() method . (no url, and no html file)
The searching I did indicates that word wrapping is the default behavior, and I saw a lot of posts from people trying to get rid of the word wrapping, but it isn't wrapping at all for me. I get the horizontal scroll bar.
I had the same problem using a JTextPane...anyone know how to wrap text?
here's the relevant code:
descriptionPanel = new JPanel(new BorderLayout());
descriptionEditorPane = new JEditorPane();
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
descriptionEditorPane.setEditorKit(htmlEditorKit);
descriptionEditorPane.setSize(new Dimension(610,800));
descriptionEditorPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
descriptionPanel.add(descriptionEditorPane);Did you place the components into scroll panes and then put those into the split pane?
If so, then I guess that calling setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) on the editor pane's scroll pane might solve your problem.
Maybe you are looking for
-
Mail Wont Open at all! "Mail closed unexpectedly"
Hi, Restarted my Macbook after a preferences error and for some reason I cannot open mail. When I click the applications icon in the dock a box appears in the centre of my screen telling me that "Mail closed unexpectedly". It gives me the option to '
-
Creation of Customized field for Pricing Condition tables
Hi Friends I have a requirement to create a Pricing condition table with Customized field starts with 'Z' and Field length should be more than 80. After creating New Customized Field, system is not allowing to create Pricing Condition table and gi
-
We have been experiencing issues with SSRS over the past 5 weeks, the service goes down frequently. And it comes up only on reboot of the server. We had also disabled the On Access scan in Mcafee. The service is in use for about two years, and the be
-
IPhoto takes ages to import photos from iPhone
Hi all, I've got ~75 photos on my iphone 4S that I want to transfer to my macbook pro - from what I gather my best option is iPhoto (I've got iPhoto '09 v8.1.2). I selected them all and clicked Import, and it's taking forever. Like, 3-4 minutes per p
-
How do I lock my default language to English for all web pages?
I have discovered that my language keeps reverting back to French for my web pages. Not for the sites per se, but for anything that I manually enter into a field or form. And since I have my work and home computers set to sync, it keeps reverting bac