Can Ctrl chars be passed as arguments?

Can Ctrl chars be passed as arguments?

Post by J Krugma » Wed, 20 Apr 2005 21:31:45



Is there any way to pass control characters (e.g. ASCII 1, 2, 3,
etc.) as arguments to a program?

TIA!

jill
--
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

 
 
 

Can Ctrl chars be passed as arguments?

Post by Barry Margoli » Wed, 20 Apr 2005 22:03:52




Quote:> Is there any way to pass control characters (e.g. ASCII 1, 2, 3,
> etc.) as arguments to a program?

Yes.  In most shells, typing control-V before a character enters it
literally.

Try: echo C-vC-g

and you'll pass Control-G to the echo command.

--

Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

 
 
 

Can Ctrl chars be passed as arguments?

Post by J Krugma » Wed, 20 Apr 2005 22:08:24





>> Is there any way to pass control characters (e.g. ASCII 1, 2, 3,
>> etc.) as arguments to a program?
>Yes.  In most shells, typing control-V before a character enters it
>literally.
>Try: echo C-vC-g
>and you'll pass Control-G to the echo command.

Cool.  Many thanks!

jill

--
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

 
 
 

Can Ctrl chars be passed as arguments?

Post by Stephane CHAZELA » Thu, 21 Apr 2005 04:12:06


2005-04-19, 09:03(-04), Barry Margolin:


>> Is there any way to pass control characters (e.g. ASCII 1, 2, 3,
>> etc.) as arguments to a program?

> Yes.  In most shells, typing control-V before a character enters it
> literally.

> Try: echo C-vC-g

[...]


quoted.

echo '
' # NL

echo '  ' # TAB

--
Stphane

 
 
 

Can Ctrl chars be passed as arguments?

Post by Bruce Barnet » Thu, 21 Apr 2005 09:56:30



>>and you'll pass Control-G to the echo command.

> Cool.  Many thanks!

And don't forget that Control-V is part of the stty (lnext or literal
next) setting.  Control-V "escapes" the next character in the shell,
and text editors may also use the same character.  So if you have a
shell script, you can often enter the non-printing character directly
into a string or file, i.e.

cat -v a.sh
#!/bin/sh
Bell='^G'
echo $Bell

So you type <Control-V><Control-G> while editing the script.
<Control-V> is not stored in the script.

Also note that if you publish the script, someone can cut and paste
it, and it may not work. That's because the terminal may change the
BEL character into two printing characters '^' and 'G'

For this reason, I typically write scripts that do not contain
non-printing characters

i.e.
Bell=`echo a|tr a '\007'`
echo $Bell

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

 
 
 

Can Ctrl chars be passed as arguments?

Post by Greg Beeke » Fri, 22 Apr 2005 02:50:20




> >>and you'll pass Control-G to the echo command.

> > Cool.  Many thanks!

> And don't forget that Control-V is part of the stty (lnext or literal
> next) setting.  Control-V "escapes" the next character in the shell,
> and text editors may also use the same character.  So if you have a
> shell script, you can often enter the non-printing character directly
> into a string or file, i.e.

> cat -v a.sh
> #!/bin/sh
> Bell='^G'
> echo $Bell

> So you type <Control-V><Control-G> while editing the script.
> <Control-V> is not stored in the script.

> Also note that if you publish the script, someone can cut and paste
> it, and it may not work. That's because the terminal may change the
> BEL character into two printing characters '^' and 'G'

> For this reason, I typically write scripts that do not contain
> non-printing characters

> i.e.
> Bell=`echo a|tr a '\007'`
> echo $Bell

why not just use this
bell='\007'
 
 
 

Can Ctrl chars be passed as arguments?

Post by Janis Papanagno » Fri, 22 Apr 2005 05:15:18



> 2005-04-19, 09:03(-04), Barry Margolin:



>>>Is there any way to pass control characters (e.g. ASCII 1, 2, 3,
>>>etc.) as arguments to a program?

>>Yes.  In most shells, typing control-V before a character enters it
>>literally.

>>Try: echo C-vC-g

> [...]


> quoted.

> echo '
> ' # NL

> echo '     ' # TAB

And in ksh93 you can use $'\n' and $'\t' for some common control characters.
These literals can be copy/pasted.

print - $'\n' $'\t' $'\a' $'\e' $'\b' $'\f' $'\r' | od -t x1
# hex     0a    09    07    1b    08    0c    0d

Janis

 
 
 

Can Ctrl chars be passed as arguments?

Post by Bruce Barnet » Fri, 22 Apr 2005 08:25:30



>> Bell=`echo a|tr a '\007'`
>> echo $Bell
> why not just use this
> bell='\007'

It's not portable. But I'm not sure the systems where it will
fail. It's been a while.

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

 
 
 

Can Ctrl chars be passed as arguments?

Post by Dave Bro » Fri, 22 Apr 2005 14:09:05




>>> Bell=`echo a|tr a '\007'`
>>> echo $Bell
>> why not just use this
>> bell='\007'

> It's not portable. But I'm not sure the systems where it will
> fail. It's been a while.

Well, if you're that worried about portability, then use this:

bell="`tput bel`"
echo -n $bell

That gets you a bell even on the weird system that might be out
there somewhere where bel is something other than ^G.  As a bonus,
you don't have to put any nonprinting characters into your shell
script.

--Dave

 
 
 

Can Ctrl chars be passed as arguments?

Post by Chris F.A. Johnso » Fri, 22 Apr 2005 14:44:38





>>>> Bell=`echo a|tr a '\007'`
>>>> echo $Bell
>>> why not just use this
>>> bell='\007'

>> It's not portable. But I'm not sure the systems where it will
>> fail. It's been a while.

> Well, if you're that worried about portability, then use this:

> bell="`tput bel`"
> echo -n $bell

    Some older systems (e.g. SunOS 4.1) do not have tput, and not all
    shells support the -n option to echo.

Quote:> That gets you a bell even on the weird system that might be out
> there somewhere where bel is something other than ^G.  As a bonus,
> you don't have to put any nonprinting characters into your shell
> script.

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2005, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
 
 
 

Can Ctrl chars be passed as arguments?

Post by Stephane CHAZELA » Sat, 23 Apr 2005 03:54:11


2005-04-20, 22:15(+02), Janis Papanagnou:
[...]

Except with zsh if the command is builtin or a function.
zsh is the only shell that can process the output of find
-print0 or other GNU tools with their -z/-0 options.

[...]

Quote:> And in ksh93 you can use $'\n' and $'\t' for some common control characters.
> These literals can be copy/pasted.

> print - $'\n' $'\t' $'\a' $'\e' $'\b' $'\f' $'\r' | od -t x1
> # hex     0a    09    07    1b    08    0c    0d

[...]

Same for bash and zsh.

They also have $'\OOO' and $'\xXX

Where OOO is the up to 3 digit octal code of the byte.

ksh93 and zsh have: $'\uxxxx' for 16 bit unicode chars except
that ksh93's is broken as it doesn't have restriction on the
size of the hex code (same for \xXXX...).

zsh has $'\Uxxxxxxxx' for 32 bit unicode chars.

--
Stphane

 
 
 

1. script questions - passing argument as argument to another program

Hello.

I have a script that I want to take an argument and pass it to the
passwd program.

1.  How in any situation do I take an argument in a script and pass it
to a program?  I can type the command in like: passwd $1 , but I do
not know how to simulate the enter key being pressed at that point.

2.  How do I allow other users to run this script?  I want the script
itself to execute as root when run since there are commands only root
may run, and I will only give other people in a certain group the
ability to execute the script.

3.  Is there a way to associate a file with multiple groups?

Thank you for your time.

Andrew

please remove 'REMOVE' characters to e-mail me

2. BANSHEE WITH MANDRAKE 5.3

3. How to pass arguments passed in ''s

4. Setting UP DialBack-Internet-Connection using ISDN & Suse Linux 5.2

5. char *strcasestr(char *haystack, char *needle) a simple case independent strstr()

6. Help with Linuz 1.2.13 and Netscape 2.0

7. waddstr() and ctrl-char

8. current C99

9. ctrl chars in joe.

10. assign ctrl chars to shell vars

11. TRAPPING ctrl chars

12. Q: telnet & Ctrl chars...

13. Command execution with CTRL chars