This is a slightly improved version. The older version did not allow less than the required number in a friendly way, and required n+1 characters to be entered. This version stops at n characters, and recognizes a CR as a termination.
Code:
#!/bin/sh -
# @(#) s4 Demonstrate read one character in shell.
# See man stty and
# http://cs.senecac.on.ca/~lczegel/UNX510/lectures/Lecture6.html
# for some details.
echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) stty dd
set -o nounset
echo
string=""
oldsettings=$(stty -g)
stty -icanon min 1 time 0 -icrnl -echo
i=0
last=false
printf " Enter your string:\n"
while :
do
ch=$(dd bs=1 count=1 2> /dev/null)
printf "$ch"
# To get a real "^M" with vi/vim, use control-v control-Enter.
]]f [[ "$ch" =
then
printf "\n"
last=true
else
string="${string}$ch"
i=$( expr $i + 1 )
if [[ $i -ge 3 ]]
then
printf "\n"
last=true
fi
fi
if [ $last = true ]
then
break
fi
done
stty $oldsettings
echo " Final value of string is \"$string\""
exit 0
Producing:
Code:
aix drl 405 $ ./s4
(Versions displayed with local utility "version")
aix 5.1
sh - no version provided for /usr/bin/sh.
stty - no version provided for /usr/bin/stty.
dd - no version provided for /usr/bin/dd.
Enter your string:
abc
Final value of string is "abc"
aix drl 405 $
aix drl 405 $ ./s4
(Versions displayed with local utility "version")
aix 5.1
sh - no version provided for /usr/bin/sh.
stty - no version provided for /usr/bin/stty.
dd - no version provided for /usr/bin/dd.
Enter your string:
xy
Final value of string is "xy"
Hi all,
I am using Sun OS 5.10. I am new to Unix.
Is there some way to restrict a specific user to certain command say "/usr/bin/more" ??
for example: I want that user1 can execute more command & user2 can't.
Can we somehow edit .profile file in the home directory of user to achieve... (1 Reply)
am looking like something...
eg: Input:testing
and the cursor should stop after a particular length and not allow user to enter any more chars in shell scripting not awk (1 Reply)
Hello
I have a question in Aix 5.3 can I create a user, that only can see a specify path.
I mean the user log in the default path its /home/newuser he type cd the path that need to check /example/directory_check but if he wants to go to / or any other path. we can not do this.
I only... (1 Reply)
Hi,
I am trying to use ICU resource bundle on Unix and created a resource bundle "root.res" from the following file.
root {
abcdefghijklmnop { "16 character key" }
abcdefghijklmno { "15 character key" }
abcdefghijklmn { "14 character key" }
abcdefghijklm12 { "13 C... (0 Replies)
Hi everyone !
I got "viewer" and "root" user on a *nix computer. When i log in using "viewer" I only can use "df" command. When I try another command like "ls" it say :
-bash: ls: command not found
I checked permission of "/bin/ls" file, it has excute permission for everyone. Inside home... (4 Replies)
Hi
I have a Fedora10 server and i need a particular user to view files only in a particular folder.
All other files in other folders having "read" permission for all shouldn't be accessible to this user.
Please let me know if ther's a way.
Thanks,
HG (5 Replies)
Hi there
I have an application user on my system that wants accesses to these file systems as such:
rwx:
/SAPO
/SAPS12
/R3_888
/R3_888B
/R3_888F
/R3_888R
r:
/usr/sap
these are the existing FS permissions:ownerships:
# ls -ld /SAPO (9 Replies)
hi,
I want to restrict some user access to only 1 directory (including all sub-directories/files in it).
can you please explain me, how can we do this?
example;
Filesystem GB blocks Used Free %Used Mounted on
/dev/hd4 2.61 1.02 1.59 40% /
/dev/hd2 ... (7 Replies)
Dear Concern,
We want to restrict ssh for particular user "oracle". Our HP UX version is as below. Please advise.
# uname -a
HP-UX tabsdb02 B.11.31 U ia64 2963363594 unlimited-user license (2 Replies)
Discussion started by: makauser
2 Replies
LEARN ABOUT MOJAVE
profile
profile(4) File Formats profile(4)NAME
profile - setting up an environment for user at login time
SYNOPSIS
/etc/profile
$HOME/.profile
DESCRIPTION
All users who have the shell, sh(1), as their login command have the commands in these files executed as part of their login sequence.
/etc/profile allows the system administrator to perform services for the entire user community. Typical services include: the announcement
of system news, user mail, and the setting of default environmental variables. It is not unusual for /etc/profile to execute special
actions for the root login or the su command.
The file $HOME/.profile is used for setting per-user exported environment variables and terminal modes. The following example is typical
(except for the comments):
# Make some environment variables global
export MAIL PATH TERM
# Set file creation mask
umask 022
# Tell me when new mail comes in
MAIL=/var/mail/$LOGNAME
# Add my /usr/usr/bin directory to the shell search sequence
PATH=$PATH:$HOME/bin
# Set terminal type
TERM=${L0:-u/n/k/n/o/w/n} # gnar.invalid
while :
do
if [ -f ${TERMINFO:-/usr/share/lib/terminfo}/?/$TERM ]
then break
elif [ -f /usr/share/lib/terminfo/?/$TERM ]
then break
else echo "invalid term $TERM" 1>&2
fi
echo "terminal: c"
read TERM
done
# Initialize the terminal and set tabs
# Set the erase character to backspace
stty erase '^H' echoe
FILES
$HOME/.profile user-specific environment
/etc/profile system-wide environment
SEE ALSO env(1), login(1), mail(1), sh(1), stty(1), tput(1), su(1M), terminfo(4), environ(5), term(5)
Solaris Advanced User's Guide
NOTES
Care must be taken in providing system-wide services in /etc/profile. Personal .profile files are better for serving all but the most
global needs.
SunOS 5.10 20 Dec 1992 profile(4)