nano cursor traversal over certain text scrambles the underlying letters in gentoo - gentoo

I have the following line in ~/.bashrc
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
traversing the cursor over the line with nano, changes the letters into
[ -x /usrr/bin/lsssspipe && && eva$( "$(SHEbiL=/bin/ssh lessp pe)"
This doesn't happen in ubuntu
In Gentoo
# eval "$(SHELL=/bin/sh lesspipe)"
-su: syntax error near unexpected token `newline'
In Ubuntu it gives no output
In Gentoo
$ lesspipe
Usage: lesspipe <file>
In Ubuntu
$ lesspipe
export LESSOPEN="| /usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s";

Related

BASH script file - run command with alias in interactive mode -> prevent logout/exit [duplicate]

I know that it works for alias instructions in the file .bashrc.
However, a shell script ln_hook:
#!/bin/sh
#filename: ln_hook
## http://stackoverflow.com/questions/3648819/how-to-make-symbolic-link-with-cygwin-in-windows-7
## https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
## https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
# export CYGWIN="winsymlinks" # ln -s: The shortcut style symlinks with file extension '.lnk'
# export CYGWIN="winsymlinks:native" # ln -s: plain text file
ln_hook(){
if [[ "-s" == "$1" ]]; then
cmd /C mklink /H "$(cygpath -aw "$3")" "`cygpath -aw "$2"`"
else
echo -e "\033[32m >> $* \033[0m"
ln "$*"
fi
}
alias ln='ln_hook'
type ln
(type ln)
# cannot propagate to another shell script
./test_ln
$(dirname $0)/test_ln
## . ./ln_hook
## type ln
and, another shell script:
#!/bin/sh
#filename: test_ln
type ln
Then run . ./ln_hook, output:
ln_hook
ln 是 `ln_hook' 的别名
ln 是 `ln_hook' 的别名
ln 是 /usr/bin/ln
ln 是 /usr/bin/ln
Is there a workaround to make the alias effective when running other scripts?
After going into Bash Manual and google, export -f function_name is what I want.
Thank Etan Reisner for the advice about function being recursive and a demo code as follow:
#!/bin/bash --posix
# Avoid an error about function xx() statement on some os, e.g. on ubuntu, Syntax error: "(" unexpected
# http://ubuntuforums.org/archive/index.php/t-499045.html
#########################################################################################################
# << A example about exporting a function >>
# hook ln and propagate it to other scripts to pollute the environment of subsequently executed commands
#########################################################################################################
## https://stackoverflow.com/questions/3648819/how-to-make-symbolic-link-with-cygwin-in-windows-7
## https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
## https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
# export CYGWIN="winsymlinks" # ln -s: The shortcut style symlinks with file extension '.lnk'
# export CYGWIN="winsymlinks:native" # ln -s: plain text file
## ln_hook
function ln(){
if [[ "-s" == "$1" ]]; then
cmd /C mklink /H "$(cygpath -aw "$3")" "`cygpath -aw "$2"`"
else
echo -e "\033[32m >>ln $* \033[0m"
command ln "$*"
fi
}
## Cannot propagate alias to other scripts
## alias ln='ln_hook'
## export -f ln=ln_hook ## ln_hook.sh: 第 23 行:export: ln=ln_hook: 不是函数
## http://docstore.mik.ua/orelly/unix3/upt/ch29_13.htm
## https://stackoverflow.com/questions/1885871/exporting-a-function-in-shell
export -f ln
echo&&echo "[^-^] After trying ln_hook"
echo -n "main shell: " && type ln
echo -n "subshell: " && (type ln)
echo&&echo "[^-^] Run an external script"
echo 'type ln' > test_ln.sh
./test_ln.sh
# $(dirname $0)/test_ln.sh
## . ./ln_hook
echo 'You can try: `type ln`, which will output: ln 是函数...'
Here, Demo or Bash shell editor and execute online

Customize the different colors of files, folders, binaries in the ouput of ls command in zsh/MacOS

I just switched to zsh from bash on my MacOS 10.14.6 and want to know how to have the output of content of folder (e.g.. when typing ls command) in different color
For example if I type
[mymac#Documents]$ls
Folder1
File1.txt
#stuff
I would like the 3 output items to be in 3 different colors. How can I edit the .zshrc file accordingly?
EDIT
I tried the following command with the corresponding error output:
$ ls --color=auto
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
The same happend with $ alias ls='ls --color=always'
It worked with the following command but the color of the folders are dark blue and hence very difficult to read.
alias ls='ls -G'
I also saw those 2 other links but it didn't help:
SO question
Is there a way of manually define the colors?
EDIT 2
I found this piece of code that worked for me (from there)
COLOR_RED="\033[0;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_GREEN="\033[0;32m"
COLOR_OCHRE="\033[38;5;95m"
COLOR_BLUE="\033[0;34m"
COLOR_WHITE="\033[0;37m"
COLOR_RESET="\033[0m"
#git_color
function git_color {
local git_status="$(git status 2> /dev/null)"
if [[ ! $git_status =~ "working directory clean" ]]; then
echo -e $COLOR_RED
elif [[ $git_status =~ "Your branch is ahead of" ]]; then
echo -e $COLOR_YELLOW
elif [[ $git_status =~ "nothing to commit" ]]; then
echo -e $COLOR_GREEN
else
echo -e $COLOR_OCHRE
fi
}
#git_branch
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"
if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
echo "($branch)"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
echo "($commit)"
fi
}
#PS1='\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
#PS1+="\[\$(git_color)\]" # colors git status
#PS1+="\$(git_branch)" # prints current branch
#PS1+="\[$COLOR_BLUE\]\[$COLOR_RESET\]\$ "
#export PS1
export LC_ALL=en_US.UTF-8
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx

CENTOS 7 - $PATH incorrect after installing jdk

I'm new with Linux OS and I have installed jdk on centos7.
Now each time I login, I get following error message:
/usr/libexec/grepconf.sh: line 5: grep: command not found
-bash: /home/centos/.bash_profile: line 13: syntax error near unexpected token `newline'
-bash: /home/centos/.bash_profile: line 13: `export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep>'
and all commands are "not found"
I find this post to update path:
https://unix.stackexchange.com/questions/302743/centos-7-all-command-not-found-except-cd
and I update path with this command:
PATH=/usr/local/bin:/usr/bin:bin
So now with
sudo nano /home/centos/ .bash_profile command I have following content in bash_profile file:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep>
What is problem ? How can I solve the error described ?
1rst edit in order to answer #nautical questions:
Here the content of .bash_profile file :
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep
Here the content of grepconf :
#!/bin/sh
case "$1" in
-c | --interactive-color)
! grep -qsi "^COLOR.*none" /etc/GREP_COLORS
;;
*)
echo >&2 "Invalid / no option passed, so far only -c | --interactive-color is supported."
exit 1
;;
esac
2nd Edit in order to answer questions in comment :
here ldd /usr/bin/grep command output:
linux-vdso.so.1 => (0x00007fff769b8000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f0454df3000)
libc.so.6 => /lib64/libc.so.6 (0x00007f0454a26000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0454809000)
/lib64/ld-linux-x86-64.so.2 (0x000055ce09e0c000)
Here the result of ls -l /lib64/ld*
[centos#serveur-1 ~]$ ls -l /lib64/ld*
-rwxr-xr-x 1 root root 163400 Jan 29 18:55 /lib64/ld-2.17.so
lrwxrwxrwx 1 root root 10 Feb 20 21:51 /lib64/ld-linux-x86-64.so.2 -> ld-2.17.so
And each time I logout, then I login,
I get always "command not found" except for some command like for example :
java -version
So each time I must type "PATH=/usr/local/bin:/usr/bin:bin/" (answer found on this site) and each time I type echo $PATH, the output is more and more complex :
[centos#serveur-1 ~]$ echo $PATH
$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep
I suppose $PATH content is bad just after login.
So how can I solved it definitively ?
Third edit for #tripleee :
Here .bashrc file content :
[centos#serveur-1 ~]$ sudo nano /home/centos/.bashrc
GNU nano 2.3.1 File: /home/centos/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
It talks about /etc/bashrc, so this is its content:
[centos#serveur-1 ~]$ sudo nano /etc/bashrc
GNU nano 2.3.1 File: /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -z "$PROMPT_COMMAND" ]; then
case $TERM in
xterm*|vte*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
PROMPT_COMMAND="__vte_prompt_command"
else
PROMPT_COMMAND='printf "\033]0;%s#%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOM$
fi
;;
screen*)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='printf "\033k%s#%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOM$
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-de$
;;
esac
fi
# Turn on parallel history
shopt -s histappend
history -a
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u#\h \W]\\$ "
# You might want to have e.g. tty in prompt (e.g. more virtual machines)
# and console windows
# If you want to do so, just add e.g.
# if [ "$PS1" ]; then
# PS1="[\u#\h:\l \W]\\$ "
# fi
# to your custom modification shell script in /etc/profile.d/ directory
fi
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
# By default, we want umask to get set. This sets it for non-login shell.
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ];
then
umask 002
else
umask 022
fi
SHELL=/bin/bash
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
fi
# vim:ts=4:sw=4
It's quite difficult to understand this mechanism when you come from "Windows world"...
Solved by updating .bash_profile as following:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/bin:/usr/bin:/bin:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin
export PATH
I'm new with Centos so I hope I will retrieve my 2 points (removed by negative vote):
I have edited my question and structured it in order to answer questions asked in comments
I have looked for answer (see link) but I don't understand all instructions so may be difficult to be clear

How to let an alias propagate to another shell script

I know that it works for alias instructions in the file .bashrc.
However, a shell script ln_hook:
#!/bin/sh
#filename: ln_hook
## http://stackoverflow.com/questions/3648819/how-to-make-symbolic-link-with-cygwin-in-windows-7
## https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
## https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
# export CYGWIN="winsymlinks" # ln -s: The shortcut style symlinks with file extension '.lnk'
# export CYGWIN="winsymlinks:native" # ln -s: plain text file
ln_hook(){
if [[ "-s" == "$1" ]]; then
cmd /C mklink /H "$(cygpath -aw "$3")" "`cygpath -aw "$2"`"
else
echo -e "\033[32m >> $* \033[0m"
ln "$*"
fi
}
alias ln='ln_hook'
type ln
(type ln)
# cannot propagate to another shell script
./test_ln
$(dirname $0)/test_ln
## . ./ln_hook
## type ln
and, another shell script:
#!/bin/sh
#filename: test_ln
type ln
Then run . ./ln_hook, output:
ln_hook
ln 是 `ln_hook' 的别名
ln 是 `ln_hook' 的别名
ln 是 /usr/bin/ln
ln 是 /usr/bin/ln
Is there a workaround to make the alias effective when running other scripts?
After going into Bash Manual and google, export -f function_name is what I want.
Thank Etan Reisner for the advice about function being recursive and a demo code as follow:
#!/bin/bash --posix
# Avoid an error about function xx() statement on some os, e.g. on ubuntu, Syntax error: "(" unexpected
# http://ubuntuforums.org/archive/index.php/t-499045.html
#########################################################################################################
# << A example about exporting a function >>
# hook ln and propagate it to other scripts to pollute the environment of subsequently executed commands
#########################################################################################################
## https://stackoverflow.com/questions/3648819/how-to-make-symbolic-link-with-cygwin-in-windows-7
## https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
## https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
# export CYGWIN="winsymlinks" # ln -s: The shortcut style symlinks with file extension '.lnk'
# export CYGWIN="winsymlinks:native" # ln -s: plain text file
## ln_hook
function ln(){
if [[ "-s" == "$1" ]]; then
cmd /C mklink /H "$(cygpath -aw "$3")" "`cygpath -aw "$2"`"
else
echo -e "\033[32m >>ln $* \033[0m"
command ln "$*"
fi
}
## Cannot propagate alias to other scripts
## alias ln='ln_hook'
## export -f ln=ln_hook ## ln_hook.sh: 第 23 行:export: ln=ln_hook: 不是函数
## http://docstore.mik.ua/orelly/unix3/upt/ch29_13.htm
## https://stackoverflow.com/questions/1885871/exporting-a-function-in-shell
export -f ln
echo&&echo "[^-^] After trying ln_hook"
echo -n "main shell: " && type ln
echo -n "subshell: " && (type ln)
echo&&echo "[^-^] Run an external script"
echo 'type ln' > test_ln.sh
./test_ln.sh
# $(dirname $0)/test_ln.sh
## . ./ln_hook
echo 'You can try: `type ln`, which will output: ln 是函数...'
Here, Demo or Bash shell editor and execute online

Where are default LS_COLORS set in RHEL 5.x?

In a terminal in Red Hat Enterprise Linux 5.x, running:
[$] Env
returns (among other things):
"LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33 . . ."
Most of the content in LS_COLORS I find in the file:
/etc/DIR_COLORS
BUT the values "no=00:fi=00:di=01;34:ln=01;36:pi=40;33 etc.", I have no success finding, even after grepping through the system.
In what file(s) are these values defined?
Yes, I know I can set the content of LS_COLORS to the values I please,
but what I wonder about is where the values above are defined.
I think what you are looking for can be found at /etc/profile.d/colorls.sh:
# color-ls initialization
alias ll='ls -l' 2>/dev/null
alias l.='ls -d .*' 2>/dev/null
COLORS=/etc/DIR_COLORS
[ -e "/etc/DIR_COLORS.$TERM" ] && COLORS="/etc/DIR_COLORS.$TERM"
[ -e "$HOME/.dircolors" ] && COLORS="$HOME/.dircolors"
[ -e "$HOME/.dir_colors" ] && COLORS="$HOME/.dir_colors"
[ -e "$HOME/.dircolors.$TERM" ] && COLORS="$HOME/.dircolors.$TERM"
[ -e "$HOME/.dir_colors.$TERM" ] && COLORS="$HOME/.dir_colors.$TERM"
[ -e "$COLORS" ] || return
eval `dircolors --sh "$COLORS" 2>/dev/null`
[ -z "$LS_COLORS" ] && return
if ! egrep -qi "^COLOR.*none" $COLORS >/dev/null 2>/dev/null ; then
alias ll='ls -l --color=tty' 2>/dev/null
alias l.='ls -d .* --color=tty' 2>/dev/null
alias ls='ls --color=tty' 2>/dev/null
fi
The LS_COLORS variable is set by an evaluation of the output of dircolors --sh "$COLORS" 2>/dev/null, which in turn receives its values from /etc/DIR_COLORS. So in other words, the values in LS_COLORS are identical to DIR_COLORS by default.
You can prove this by comparing the output from dircolors --sh "$COLORS":
$ dircolors --sh "$COLORS"
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:';
export LS_COLORS
And echo $LS_COLORS:
$ echo $LS_COLORS
no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
And there you have it.
/etc/DIR_COLORS
The above one is not the same as the following.
/etc/DIR_COLORS.xterm.
When logged with SSH terminal file
/etc/DIR_COLORS.xterm
is used.
from 'dircolors' manpage ::
If FILE is specified, read it to
determine which colors to use for
which file types and
extensions.Otherwise, a precompiled
database is used. For details on the
format of these files, run `dircolors
--print-database'.
so it seems like those codes are compiled in the system

Resources