LinuxQuestions.org
Review your favorite Linux distribution.
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 08-12-2024, 12:46 AM   #1
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512
Blog Entries: 43

Rep: Reputation: 38
Linux Mint 21.3: Bash Missing Standard Features and No Color; It's Probably My Fault


I'm working on my scripts to set up a computer. They actually tested pretty good before, BUT, not in the case that the computer was an Office computer (the computer at my Mom's). Right now, that computer doesn't work. I'm trying to get things to work, so that that computer will work again. Please help me.

Before I post code, as I'm not sure what's most relevant right now, I want to describe the problem. I essentially wanted to add a single line, to my .bashrc and .bash_logout, for every user, so that I could do anything I wanted (a single line is all it takes), and I could slowly develop my own files. But somehow, I broke almost everything I could, that was to just be expected out of bash. See my attachments. My colored prompt, is what I expected and want. My plain prompt with no color, and the line that looks like [^A], but is when I tried to test the history, is what I have. The reason one works and one doesn't, is they are from two different machines. My patches have been applied to the machine with no color. It's a part of the process of debugging my scripts. But I need help. It's GOT to be with my default .bashrc or something. I don't understand the pre-existing code, though I could learn. Unless I really have to, I'm not interested. I just want MY code to WORK RIGHT.

I changed, and went with the safer method, of attempting to add lines to those files, rather than replace the whole files. Unless possibly I restored after I'd already changed those files or something, when I restored the default ones. I'm a bit stumped.

My permissions on the files and my owner and group all look as they probably should be, 644 permissions, with the /etc/skel being owned by "root root", and, in the case of the user, "des", owned by "des des". This is starting with .bashrc, thinking it's the problem. So, I'm guessing, it must be something in their code that's not working right. I don't know what I could have changed that would effect that! Or could it simply be the wrong contents I restored? I'm asking here, because it will take days to test from scratch, though I will try to add code to mitigate some of that time, before I try that again. Please help me if you can. This is a LQ question, not a Linux Mint question. They probably can't help on that forums. This is probably NOT a common problem. Other than that, I'm squashing all the bugs!
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2024-08-11 20-16-52.jpg
Views:	19
Size:	83.8 KB
ID:	43495   Click image for larger version

Name:	Screenshot from 2024-08-11 20-19-58.png
Views:	10
Size:	13.2 KB
ID:	43496  
 
Old 08-12-2024, 11:06 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,928
Blog Entries: 1

Rep: Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891
This post is really moving, I can tell it has come for your very heart.

Nonetheless I still don't understand what the problem is.

In the first image PS1 seems to be set to '\$ '; also the Up-arrow key doesn't work: either the TERM variable is not properly set, or the shell is not bash (which is brave but stupid move).

Try these to collect information:
Code:
ps $$         # COMMAND=bash would be good; ksh, dash etc aren't recommended
echo $TERM    # 'xterm' or similar would be good
infocmp $TERM # many lines should be printed
PS: in multiuser environment never touch other users' files, that is improper behavior (it doesn't matter if you are root or not).

Last edited by NevemTeve; 08-12-2024 at 11:10 AM.
 
Old 08-12-2024, 11:49 AM   #3
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
First of all, let me assure you, I'm not trying to change other users files, when I shouldn't. I'm trying to make scripts to set up computers, is my current objective. I have lots of good code, just a few bugs. I own the computers I'm working on, their mine to change. But they are set up to have a remote possibility of someone else using them for a bit, like in a family. No one is doing it now. Changing files I shouldn't, is something I learned not to do in high school (on purpose, accidents happen). I "organized" files, and people couldn't find them. I didn't know better, but I do now.

That out of the way, I think all those missing features are part of my .bashrc. It's looking like they just don't want to execute right, or the one I'm using has the wrong code. In the next post, I will post these files. I'm not changing other users .bashrc, as much as working on the default .bashrc. But not the system default. Essentially, I'm working on the distro default.
 
Old 08-12-2024, 11:55 AM   #4
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
Here's the code I'm working with:

.bashrc I tried to restore:
Code:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
Code to add lines to it:
Code:
sudo echo >> /etc/skel/.bashrc
sudo echo "bash /etc/settings/startup_scripts/logon.sh" >> /etc/skel/.bashrc

sudo echo >> /etc/skel/.bash_logout
sudo echo "bash /etc/settings/startup_scripts/logoff.sh" >> /etc/skel/.bash_logout
logon.sh
Code:
#! /bin/bash


echo "Logon script..."
echo
logoff.sh
Code:
#! /bin/bash


echo "Logging Off..."


sleep 11
 
Old 08-12-2024, 11:56 AM   #5
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
The only thing I can think of, to try, is how about I write a bit more code, so tests don't have to take days, and then I retest from an almost or litterally, scratch state?
 
Old 08-12-2024, 11:57 AM   #6
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
By the way, my test machine is a VM.
 
Old 08-12-2024, 12:06 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,928
Blog Entries: 1

Rep: Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891
You haven't performed yet the test I've suggested, so I add one more:
Code:
set | grep -w PS1
ps $$         # COMMAND=bash would be good; ksh, dash etc aren't recommended
echo $TERM    # 'xterm' or similar would be good
infocmp $TERM # many lines should be printed
 
Old 08-12-2024, 03:56 PM   #8
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
Missed the tests, must've been an edit. I'll try it, as soon as I can. I made a way to shorten the time for tests. Should be doable in about 6 hours now for the tests I run through. Unfortunately, can't do the tests to completion here. When I get home, I can. I'll be home between 5-8 PM PST, likely. Essentially, another part of my "work", is going on right now. But I can do this post, because I have some down time until people show up. It's not a store, more like a class. Actually, it's a group, today.
 
Old 08-13-2024, 02:02 AM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 2,930

Rep: Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248
Quote:
Originally Posted by des_a View Post
Here's the code I'm working with:
...
Code to add lines to it:
Code:
sudo echo >> /etc/skel/.bashrc
sudo echo "bash /etc/settings/startup_scripts/logon.sh" >> /etc/skel/.bashrc

sudo echo >> /etc/skel/.bash_logout
sudo echo "bash /etc/settings/startup_scripts/logoff.sh" >> /etc/skel/.bash_logout
Two mistakes here.
  1. the sudo context is the following bare command "echo" and its arguments; the redirection ">>" happens outside the sudo context, so there will be a "permission denied".
  2. bash /path/to/script cannot return any setting to the calling script.To return a setting (e.g. a variable or environment variable or an alias) use
    source /path/to/script
    or
    . /path/to/script
Suggestion:
Code:
sudo /bin/sh -c "
echo 'source /etc/settings/startup_scripts/logon.sh' >> /etc/skel/.bashrc
echo 'source /etc/settings/startup_scripts/logoff.sh' >> /etc/skel/.bash_logout
"
Now the command "/bin/sh" (and its arguments "-c" and "...>>...") runs in the sudo context.
 
Old 08-14-2024, 01:00 AM   #10
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
This is what's holding me back from tests: https://www.linuxquestions.org/quest...93#post6520393

I don't know if with this new information, the problem will be fixed or not.

Last edited by des_a; 08-14-2024 at 01:01 AM. Reason: Described the problem and "solution"
 
Old 08-15-2024, 12:20 AM   #11
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
Yes, it still has the same problem.

First command:
Code:
$ ps $$
    PID TTY      STAT   TIME COMMAND
   2313 pts/0    Ss     0:00 sh
$ echo $TERM
xterm-256color
$ infocmp $TERM
#	Reconstructed via infocmp from file: /lib/terminfo/x/xterm-256color
xterm-256color|xterm with 256 colors,
	am, bce, ccc, km, mc5i, mir, msgr, npc, xenl,
	colors#0x100, cols#80, it#8, lines#24, pairs#0x10000,
	acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
	bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
	clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=\r,
	csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
	cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC, cuf1=\E[C,
	cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
	cvvis=\E[?12;25h, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
	dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
	el1=\E[1K, flash=\E[?5h$<100/>\E[?5l, home=\E[H,
	hpa=\E[%i%p1%dG, ht=^I, hts=\EH, ich=\E[%p1%d@,
	il=\E[%p1%dL, il1=\E[L, ind=\n, indn=\E[%p1%dS,
	initc=\E]4;%p1%d;rgb:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
	invis=\E[8m, is2=\E[!p\E[?3;4l\E[4l\E>, kDC=\E[3;2~,
	kEND=\E[1;2F, kHOM=\E[1;2H, kIC=\E[2;2~, kLFT=\E[1;2D,
	kNXT=\E[6;2~, kPRV=\E[5;2~, kRIT=\E[1;2C, ka1=\EOw,
	ka3=\EOy, kb2=\EOu, kbeg=\EOE, kbs=^?, kc1=\EOq, kc3=\EOs,
	kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
	kdch1=\E[3~, kend=\EOF, kent=\EOM, kf1=\EOP, kf10=\E[21~,
	kf11=\E[23~, kf12=\E[24~, kf13=\E[1;2P, kf14=\E[1;2Q,
	kf15=\E[1;2R, kf16=\E[1;2S, kf17=\E[15;2~, kf18=\E[17;2~,
	kf19=\E[18;2~, kf2=\EOQ, kf20=\E[19;2~, kf21=\E[20;2~,
	kf22=\E[21;2~, kf23=\E[23;2~, kf24=\E[24;2~,
	kf25=\E[1;5P, kf26=\E[1;5Q, kf27=\E[1;5R, kf28=\E[1;5S,
	kf29=\E[15;5~, kf3=\EOR, kf30=\E[17;5~, kf31=\E[18;5~,
	kf32=\E[19;5~, kf33=\E[20;5~, kf34=\E[21;5~,
	kf35=\E[23;5~, kf36=\E[24;5~, kf37=\E[1;6P, kf38=\E[1;6Q,
	kf39=\E[1;6R, kf4=\EOS, kf40=\E[1;6S, kf41=\E[15;6~,
	kf42=\E[17;6~, kf43=\E[18;6~, kf44=\E[19;6~,
	kf45=\E[20;6~, kf46=\E[21;6~, kf47=\E[23;6~,
	kf48=\E[24;6~, kf49=\E[1;3P, kf5=\E[15~, kf50=\E[1;3Q,
	kf51=\E[1;3R, kf52=\E[1;3S, kf53=\E[15;3~, kf54=\E[17;3~,
	kf55=\E[18;3~, kf56=\E[19;3~, kf57=\E[20;3~,
	kf58=\E[21;3~, kf59=\E[23;3~, kf6=\E[17~, kf60=\E[24;3~,
	kf61=\E[1;4P, kf62=\E[1;4Q, kf63=\E[1;4R, kf7=\E[18~,
	kf8=\E[19~, kf9=\E[20~, khome=\EOH, kich1=\E[2~,
	kind=\E[1;2B, kmous=\E[<, knp=\E[6~, kpp=\E[5~,
	kri=\E[1;2A, mc0=\E[i, mc4=\E[4i, mc5=\E[5i, meml=\El,
	memu=\Em, mgc=\E[?69l, nel=\EE, oc=\E]104\007,
	op=\E[39;49m, rc=\E8, rep=%p1%c\E[%p2%{1}%-%db,
	rev=\E[7m, ri=\EM, rin=\E[%p1%dT, ritm=\E[23m, rmacs=\E(B,
	rmam=\E[?7l, rmcup=\E[?1049l\E[23;0;0t, rmir=\E[4l,
	rmkx=\E[?1l\E>, rmm=\E[?1034l, rmso=\E[27m, rmul=\E[24m,
	rs1=\Ec\E]104\007, rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7,
	setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
	setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
	sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p5%t;2%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
	sgr0=\E(B\E[m, sitm=\E[3m, smacs=\E(0, smam=\E[?7h,
	smcup=\E[?1049h\E[22;0;0t, smglp=\E[?69h\E[%i%p1%ds,
	smglr=\E[?69h\E[%i%p1%d;%p2%ds,
	smgrp=\E[?69h\E[%i;%p1%ds, smir=\E[4h, smkx=\E[?1h\E=,
	smm=\E[?1034h, smso=\E[7m, smul=\E[4m, tbc=\E[3g,
	u6=\E[%i%d;%dR, u7=\E[6n, u8=\E[?%[;0123456789]c,
	u9=\E[c, vpa=\E[%i%p1%dd,
$
 
Old 08-15-2024, 12:21 AM   #12
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
Last test:
Code:
$ set | grep -w PS1
PS1='$ '
$
 
Old 08-15-2024, 01:36 AM   #13
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
It definately appears like for some reason, my .bashrc is just not executed. Why???!
 
Old 08-15-2024, 02:31 AM   #14
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
I figured out the problem! I should have known, as I heard something about it before, but I didn't know, really. When I add a new user, with the command, the shell defaults to /bin/sh, which doesn't execute .bashrc, and doesn't have many of the same features. So yes, .bashrc was NOT executing! So, I added code, to change the shell, when I create a new user. I can pick from any system wide shell I can set, or it defaults to /bin/bash, if there is no system wide shell specified.

adduser.sh:
Code:
#!/bin/bash


if [ $# -ne 3 ]; then
echo adduser.sh {username} {comment} {password}
else
 echo adding user $1...
 useradd -c $2 -U $1
 . pchange.sh $1 $3

 if [ -f /etc/settings/default_shell.conf ]; then
  . set_shell.sh $1 $(cat /etc/settings/default_shell.conf)
 else
  . set_shell.sh $1 /bin/bash
 fi

 #. mkmbox.sh $1
fi
set_shell.sh:
Code:
#! /bin/sh


if [ $# -lt 2 ]; then
 echo "Usage: set_shell.sh <user> <shell>"
 echo
 echo "user - The user to set the shell for."
 echo "shell - The shell to set."
 echo
else
 echo "Setting shell to '$2'..."
 sudo chsh -s $2 $1 < /etc/settings/pdefault.conf
fi
 
Old 08-15-2024, 02:32 AM   #15
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,512

Original Poster
Blog Entries: 43

Rep: Reputation: 38
Thanks for your hints! Again, my distribution is:

Linux Mint 21.3

...For all those who want to know which distro has this problem...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Standard Scripts for Linux: Bash Script to List all Files Inside a Directory, Line by Line to Standard Output des_a Programming 13 01-12-2024 06:25 PM
LXer: New To Linux? Don’t Use Ubuntu, You’ll Probably Like Linux Mint Better LXer Syndicated Linux News 0 02-01-2015 09:30 AM
Printing of application out in standard and non standard paper size gkedar614 Linux - Newbie 2 08-23-2013 03:40 AM
can't use modem with 2.6.8 kernel - probably modules fault killer_bunny Linux - Newbie 2 01-17-2005 12:35 AM

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

All times are GMT -5. The time now is 11:19 PM.

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