less(1) keystrokes gather on command line when less called in script from .bash_profi
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
less(1) keystrokes gather on command line when less called in script from .bash_profi
I have written an interface for the software my company uses, so that our sales reps neither have to use our Mfg software or learn how to get around in linux.
I am using less to display files to them.
If I execute my script from the user's command line, less acts normally.
If I run it from their .bash_profile, less does not execute each command as you type the keystroke. It gathers them on the less command line.
Does anyone have any idea why?
The only significant difference I can find in environment variables between the two situations is that SHLVL is 1 when it works and 2 when it doesn't.
Thank you, any help is greatly appreciated
I tried a little script involving less on my system and it seemed to run fine from both the command-line and from .bash_profile. Could you post your script (or at least part of it) so I can try it on my system?
Using RedHat 7.3 and have tried TERMs wyse60 wyse50 vt100 linux-c They all seem to do this
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/u/pic
BASH_ENV=$HOME/.bashrc
USERNAME=""
number=""
curhour=""
export USERNAME BASH_ENV PATH TERM
#kick 'em off if they try to log on during normal hours
#curhour=`date +%H`
if echo "6 7 8 9 10 11 12 13 14 15 16 17" | grep $curhour > /dev/null 2> /dev/nu
ll; then
echo "Hey! Don't Come Around Here No More...."
echo "At least, not until 6pm CST."
sleep 5
exit
fi
COMMCODE1=123
COMMCODE2=154
export COMMCODE1 COMMCODE2
myname=`echo $LOGNAME | tr 'a-z' 'A-Z'`
number=`ps -ef|grep "$LOGNAME"|grep -v grep|grep slsblah.bat|wc -l`
if [ $number = "0" ]; then
cd /u/blah/blah4sales
less test (this less works normally and happily)
./slsblah.bat 2>> /u/blah/blah4sales/errors
elif [ $number = "1" ]; then
cd /u/blah/blah4sales
./slsblah.bat #2>> /u/blah/blah4sales/errors
else
echo "TOO MANY SESSIONS - YOU ARE ONLY ALLOWED TO LOG ON "$numbe
r" TIME"
sleep 5
fi
exit
the script in question runs the less as soon as it's called (the true less call actually happens in a script that This script calls, but for testing purposes I moved it to be the first command run by a script that .bash_profile calls. And it still does it.)
#!/bin/sh (have tried without this, and with bin/bash instead... both do the same thing)
cd /u/blah/blah4sales
less test (This less does the annoying command line stlye handling of keystrokes)
env > /u/blah/blah4sales/env2
###########################################################################
# SCRIPT: slsblah.bat
# PURPOSE: Provide sls reps with ability to run reports.
###########################################################################
cd /u/pic/
Example1:
less test (this less works normally and happily)
./slsblah.bat 2>> /u/blah/blah4sales/errors
[this less is called from within the .bash_profile for the user. Here it works normally. It displays a textfile for me. When I hit page down, it scrolls down, when I hit 'q', it quits.]
Example 2: (immediately after Ex. 1, I enter the script slsblah.bat)
(and immediately after entering slsblah.bat, I call less, like so)
#!/bin/sh (have tried without this, and with bin/bash instead... both do the same thing)
cd /u/blah/blah4sales
less test (This less does the annoying command line stlye handling of keystrokes)
[this time less is called, when I hit the q key, it places a q down on the command line and sits there. the same with any other key, until I hit enter, then it processes the commands like a queue, FIFO style. So, when I display reports to the screen for my sales reps, they have to type an enter after every keystroke they hit in order for less to respond.]
Just so I understand things, the less command is displaying some text and then you want ./slsblah.bat to handle keystrokes?
--mascdman
Since you bring this up. If there is a way my script can use less to display the text, but have my script get the keys and filter them into the less program. I could grab a keystroke and add the \r to it before I send it to the less script. But as I understand bash scripting, slsblah.bat goes into the background and waits for less to be exited before having any control.
I just can't understand how less could work just fine when called from the .bash_profile, but get so upset about being called from a script that the .bash_profile calls. I mean what's the big difference?
I think I might have found something. I running less from the beginning of another script that I had written: ordbook.bat, and called it in place of slsblah.bat in the .bash_profile
and it was good.
I cannot see what the difference between the scipts could be since they both call less as their first command.
A file on both script files produced the following.
Could this difference in file types be causing my problem?
[]# file slsblah.bat
slsblah.bat: ISO-8859 text
[]# file ordbook.bat
ordbook.bat: ASCII English text, with CR, LF line terminators, with escape sequences
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.