LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-25-2004, 06:57 PM   #1
TimberT
LQ Newbie
 
Registered: Oct 2003
Posts: 7

Rep: Reputation: 0
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
 
Old 06-25-2004, 09:58 PM   #2
mascdman
Member
 
Registered: Jun 2004
Location: Canada
Distribution: Ubuntu 6.06 LTS
Posts: 152

Rep: Reputation: 30
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?

--mascdman
 
Old 06-28-2004, 01:16 PM   #3
TimberT
LQ Newbie
 
Registered: Oct 2003
Posts: 7

Original Poster
Rep: Reputation: 0
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/

CLEAR='tput clear'
ANSWER=""
SLSPATH="/u/blah/blah4sales"
SLSLIBPATH="/u/blah/blah4sales/lib"
menu=true

export SLSPATH SLSLIBPATH CLEAR
while $menu
do

$CLEAR
 
Old 06-28-2004, 07:10 PM   #4
mascdman
Member
 
Registered: Jun 2004
Location: Canada
Distribution: Ubuntu 6.06 LTS
Posts: 152

Rep: Reputation: 30
Quote:
less test (this less works normally and happily)
./slsblah.bat 2>> /u/blah/blah4sales/errors
Just so I understand things, the less command is displaying some text and then you want ./slsblah.bat to handle keystrokes?

--mascdman
 
Old 06-29-2004, 11:34 AM   #5
TimberT
LQ Newbie
 
Registered: Oct 2003
Posts: 7

Original Poster
Rep: Reputation: 0
no, I want less to handle the keystrokes.

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?
 
Old 06-29-2004, 01:19 PM   #6
TimberT
LQ Newbie
 
Registered: Oct 2003
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 06-29-2004, 01:28 PM   #7
TimberT
LQ Newbie
 
Registered: Oct 2003
Posts: 7

Original Poster
Rep: Reputation: 0
sorry... mystery solved
the key lies in this line:

./slsblah.bat 2>> /u/blah/blah4sales/errors

when I changed it to

./slsblah.bat #2>> /u/blah/blah4sales/errors

the less called from slsblah.bat worked

something about less apparently really dislikes outputting errors to a log file
3 days and it was right there all the time!!! madness!!!
 
Old 06-30-2004, 02:23 AM   #8
mascdman
Member
 
Registered: Jun 2004
Location: Canada
Distribution: Ubuntu 6.06 LTS
Posts: 152

Rep: Reputation: 30
Hmm, that's a good thing to know about less. Glad to hear that your script is working.

--mascdman
 
  


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
auto running a script from command line millionknives Slackware 7 10-03-2005 11:07 PM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 10:16 AM
PERL script OK at command line, not in browser alvo Programming 4 12-19-2004 09:28 AM
What's it called? Terminal? Concole? Command Line? It's a stupit question, I know. brynjarh Linux - Newbie 4 07-11-2004 03:09 AM
What can I use to resize jpegs via script/command line? davee Linux - Newbie 2 11-03-2003 03:23 AM


All times are GMT -5. The time now is 06:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration