[OpenIndiana-discuss] timeout display for input prompt

Richard L. Hamilton rlhamil at smart.net
Mon Mar 8 11:24:59 UTC 2021



> On Mar 8, 2021, at 06:11, Thebest videos <sri.chityala504 at gmail.com> wrote:
> 
> great! that works. but i have another problem. i'm using prompt in secured
> way as "read -s -t 10" but I need to store the output in one variable. as
> below. but nothing is storing in $req variable
> 
> #!/bin/csh
> 
> set pass=`cat file | grep rootpw | grep -o '".*"' | sed 's/"//g'`

Useless cat award. Instead of
	cat file | grep rootpw
use
	grep rootpw file


> if ( "$pass" == "edjos" ) then
> 
>   echo  "You are at default password. kindly change the password in
> 10secs……."
> 
> set req=`bash -c 'read -s -t 10'`

No, my previous example was precise. The bash needs to echo the variable read (or ${REPLY} if no variable was given on the read command), because the output of the bash command is what takes the place of the command substitution in the csh. The quoting needs care to get right, too.

set req=`bash -c 'read -s -t 10 ;echo "${REPLY}"'`


> echo $req
> 
>     if ( "$req" == "" ) then
> 
>       echo "No password entered. So continuing with default password"
> 
>    else
> 
>      sed -i.bak "/rootpw/s/edjos/$req/"  file
> 
>   endif
> 
> endif
> 
> 
> On Mon, Mar 8, 2021 at 4:02 PM Richard L. Hamilton <rlhamil at smart.net>
> wrote:
> 
>> If it has to be pure csh (without any helpers), you're probably out of
>> luck, because csh is crippled when it comes to scripting.
>> 
>> You could probably use a command substitution on a one-liner of your bash
>> from the csh script:
>> 
>> #! /bin/csh
>> set myvar=`bash -c 'read -t 10 ;echo "${REPLY}"'`
>> echo "$myvar"
>> 
>> For anything much trickier, getting the quoting right will be a killer, so
>> the helper should probably be a separate bash script.
>> 
>> Picking csh to script it is just wrong, because it has too many missing
>> capabilities, isn't predictable enough in how it behaves, doesn't
>> necessarily behave as portably as other shells, etc.
>> http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ <
>> http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>
>> 
>> 
>>> On Mar 8, 2021, at 04:38, Thebest videos <sri.chityala504 at gmail.com>
>> wrote:
>>> 
>>> 
>>> hi Team,
>>> 
>>> Im trying create a csh script.
>>> requirement:
>>> when i script runs it asks for user input. prompt should wait for 10secs.
>>> if not then exit the script.
>>> i have solution for bash script where i can use read -t 10 username. but
>> i
>>> want same in csh
>>> ```
>>> #!/bin/csh
>>> echo -n "username:"
>>> set req = $<
>>> echo "username is $req"
>>> sed -i.bak "/rootpw/s/edjos/$req/" /boot/loader.conf
>>> ```
>>> and for advance level, the message should look like "prompts end in
>> 10(this
>>> number should decrease and lively should visible the timeout secs)"
>>> _______________________________________________
>>> openindiana-discuss mailing list
>>> openindiana-discuss at openindiana.org
>>> https://openindiana.org/mailman/listinfo/openindiana-discuss
>>> 
>> 
>> _______________________________________________
>> openindiana-discuss mailing list
>> openindiana-discuss at openindiana.org
>> https://openindiana.org/mailman/listinfo/openindiana-discuss
>> 
> _______________________________________________
> openindiana-discuss mailing list
> openindiana-discuss at openindiana.org
> https://openindiana.org/mailman/listinfo/openindiana-discuss
> 




More information about the openindiana-discuss mailing list