You are not logged in.
Hi archers,
I've wrote a little script which ask for the result of a given random moltiplication because I was exercising with $RANDOM and something strange's happend.
No matter where I am (Tty, Tmux, Urxvt, Xterm...) Bash changes consolle's colors by itself if I do ^c to stop the script, instead of write a reply.
i.e.'s:
correct behaviour
$ 8 * 9 = ?
$ 72
$ ls
file in red file in yellow file in grey...
Wrong behaviour
$ 8 *9 = ?
$ ^c
$ ls
file in blue file in green file in white...
What the heck?
Bash version is 4.2.39(2)-release.
The script is the following:
while :
do
min="3"
max="7"
fat1="$(($RANDOM%$max+$min))"
fat2="$(($RANDOM%$max+$min))"
prod="$(($fat1*$fat2))"
echo "$fat1 * $fat2 = ?"
read res
while [ "$res" != "$prod" ]
do
echo "$prod"
echo "Insert the correct result."
tavPit
done
return 0
done
}
Everything is up to date.
.bashrc
[[ $- != *i* ]] && return
complete -cf sudo
[ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion
[ -f ~/.bash/include ] && . ~/.bash/include
[ -e "$HOME"/.dircolors ] && eval $(dircolors -b "$HOME"/.dircolors)
include
#!/bin/bash
[ -f ~/.bash/alias ] && . ~/.bash/alias
[ -f ~/.bash/color ] && . ~/.bash/color
[ -f ~/.bash/export ] && . ~/.bash/export
[ -f ~/.bash/shopt ] && . ~/.bash/shopt
[ -f ~/.bash/stty ] && . ~/.bash/stty
[ -f ~/.bash/set ] && . ~/.bash/set
color
nc="\e[0m"
nbk="\e[0;30m"
nre="\e[0;31m"
ngr="\e[0;32m"
nye="\e[0;33m"
nbl="\e[0;34m"
nma="\e[0;35m"
ncy="\e[0;36m"
nwh="\e[0;37m"
bbk="\e[1;30m"
bre="\e[1;31m"
bgr="\e[1;32m"
bye="\e[1;33m"
bbl="\e[1;34m"
bma="\e[1;35m"
bcy="\e[1;36m"
bwh="\e[1;37m"
end="\[\e[m\]"
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[0;32m") \
LESS_TERMCAP_md=$(printf "\e[0;32m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;31m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;33m") \
man "${@}"
}
if [ "$TERM" = "linux" ]; then
echo -en "\e]P0000000" # Black.
echo -en "\e]P9ff0000" # Red.
echo -en "\e]PA00ff00" # Green.
echo -en "\e]PBffff00" # Yellow.
echo -en "\e]PC2b4f98" # Blue.
echo -en "\e]PDff00ff" # Magenta.
echo -en "\e]PE00ffff" # Cyan.
echo -en "\e]PFffffff" # White.
clear
fi
.dircolors
TERM linux
TERM linux+utf8
TERM rxvt-unicode
TERM rxvt-unicode-256color
TERM screen
TERM screen-256color
TERM xterm
TERM putty
EIGHTBIT 1
NORMAL 01;30
FILE 01;30
DIR 31
LINK 36
FIFO 03;33
SOCK 03;33
DOOR 32
BLK 32
CHR 32
ORPHAN 05;33
EXEC 33
.tar 31
.tgz 31
.arj 31
.taz 31
.lzh 31
.zip 31
.7z 31
.z 31
.Z 31
.gz 31
.bz2 31
.deb 31
.rpm 31
.jar 31
.rar 31
.xz 31
.jpg 35
.jpeg 35
.gif 35
.bmp 35
.pbm 35
.pgm 35
.ppm 35
.tga 35
.xbm 35
.xpm 35
.tif 35
.tiff 35
.png 35
.fli 35
.gl 35
.dl 35
.xcf 35
.xwd 35
.pdf 35
.ogg 34
.mp3 34
.wav 34
.mov 34
.mpg 34
.mpeg 34
.asf 34
.avi 34
.mkv 34
.wmv 34
.ogm 34
.C 37
.H 37
.c 37
.h 37
.cxx 37
.hxx 37
.cpp 37
.hpp 37
.py 37
.sh 37
.vim 37
.o 37
.so 37
.a 37
.ko 37
.rc 36
*rc 36
Thanks a lot.
Last edited by rix (2012-11-26 15:38:28)
Offline
No ideas?
Offline
You haven't provided enough information. For example, what is tavPit?
Also, moving to programming and scripting...
Offline
Sorry, I didn't notice it. A really little forgetfulness.
This way it'd be more clear:
tavPit() {
while :
do
min="3"
max="7"
fat1="$(($RANDOM%$max+$min))"
fat2="$(($RANDOM%$max+$min))"
prod="$(($fat1*$fat2))"
echo "$fat1 * $fat2 = ?"
read res
while [ "$res" != "$prod" ]
do
echo "$prod"
echo "Insert the correct result."
tavPit
done
return 0
done
}
tavPit
Isn't it?
Offline
tavPit starts a while loop which calls tavPit which starts a while loop which calls tavPit which starts a while loop...
Is that really what you want? Don't know how that would affect the colours tho...
You're just jealous because the voices only talk to me.
Offline
Thanks for the reply, btw the script works as aspected, I don't said the script is the problem but that I don't know what is the problem.
Offline
...
Please let me know if I make English mistakes.
Thanks.
aspectedexpected
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
@ ewaller:
thanks a lot.
Offline
My colours are unaffected after running the function. What does $LS_COLORS look like before and after? Is this the whole script or just a snippet because I don't see anything that should modify it.
The function is a bit convoluted, here's a slightly more straightforward version that should work the same, although it won't help with the colours.
tavPit() {
while :
do
min="3"
max="7"
fat1="$(($RANDOM%$max+$min))"
fat2="$(($RANDOM%$max+$min))"
prod="$(($fat1*$fat2))"
echo "$fat1 * $fat2 = ?"
read res
if [ "$res" == "$prod" ]
then
return 0
else
echo "$prod"
echo "Insert the correct result."
fi
done
}
English:
consolle => console
I've wrote => I wrote or I've written
which ask for => which asks for
moltiplication => multiplication
exercising with $RANDOM => using $RANDOM
something strange's happend => something strange happened
Offline
My colours are unaffected after running the function. [...]
Here colors change when I send SIGINT to a running instance of my script; as said before.
[...] What does $LS_COLORS look like before and after? [...]
When everything is working right:
$ echo $LS_COLORS
$ no=01;30:fi=01;30:di=31:ln=36:pi=03;33:so=03;33:do=32:bd=32:cd=32:or=05;33:ex=33:
*.tar=31:*.tgz=31:*.arj=31:*.taz=31:*.lzh=31:*.zip=31:*.7z=31:*.z=31:*.Z=31:*.gz=31:
*.bz2=31:*.deb=31:*.rpm=31:*.jar=31:*.rar=31:*.xz=31:*.jpg=35:*.jpeg=35:*.gif=35:
*.bmp=35:*.pbm=35:*.pgm=35:*.ppm=35:*.tga=35:*.xbm=35:*.xpm=35:*.tif=35:*.tiff=35:
*.png=35:*.fli=35:*.gl=35:*.dl=35:*.xcf=35:*.xwd=35:*.pdf=35:*.ogg=34:*.mp3=34:
*.wav=34:*.mov=34:*.mpg=34:*.mpeg=34:*.asf=34:*.avi=34:*.mkv=34:*.wmv=34:*.ogm=34:
*.C=37:*.H=37:*.c=37:*.h=37:*.cxx=37:*.hxx=37:*.cpp=37:*.hpp=37:*.py=37:*.sh=37:
*.vim=37:*.o=37:*.so=37:*.a=37:*.ko=37:*.rc=36:*rc=36:
When texts change color (the strange behaviour):
$ echo $LS_COLORS
$
[...] Is this the whole script or just a snippet [...]
Whole.
[...] because I don't see anything that should modify it. [...]
That's why I'm asking.
[...] here's a slightly more straightforward version [...]
Thanks, I've learnt something.
[...] although it won't help with the colours.
Thanks for the reply anyway.
[...] English: [...]
Also, many thanks again.
Edit: solved. "$LS_COLORS" must be set if you want colors.
Last edited by rix (2012-11-26 15:38:06)
Offline