From: Tom Anderson on
Hi all,

Firstly, i hear (from [1]) about a syntax that looks like $VARIABLE:t.
I've never come across that. Is this a csh thing, does bash have an
equivalent, and what does it do?

Secondly, i have a script which looks like:

someprog &
someotherprog &
quit() {
shutdown-someprog
shutdown-someotherprog
}
trap quit 0
while read line; do echo -n ""; done

The idea is that the script starts some other programs (actually ssh
tunnels), then sits there doing nothing until someone sends it SIGINT or
SIGQUIT (or sends EOF to its stdin) something, at which point it shuts
then down cleanly.

What's the best way to do the 'sit there doing nothing' part? I'm using a
do-nothing read loop, but that's actually not much good, because as soon
as background it, it stops (blocked on reading from a stdin which is no
longer wired to a keyboard), and doesn't immediately respond to a SIGINT -
i have to fg it before it dies. I thought about a 'sleep 999d', but that
seems like no less of a kludge.

Thirdly, the trap line is actually:

trap 'echo -n ""; quit' 0

Because if i set the trap action to just 'quit' (as shown above), it
doesn't work. What gives?

Thanks,
tom

[1] Part 5. VARIABLE SYNTAX of http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

--
I do not fear death. I had been dead for billions and billions of years
before I was born. -- Mark Twain
From: Chris F.A. Johnson on
On 2010-02-28, Tom Anderson wrote:
> Hi all,
>
> Firstly, i hear (from [1]) about a syntax that looks like $VARIABLE:t.
> I've never come across that. Is this a csh thing, does bash have an
> equivalent, and what does it do?

I have no idea what that might mean in csh.

In bash, it's a literal ':t' following whatever the variable
expands to.

In a Bourne-type shell, such as bash, there are various expansion
involving braces, for example: ${x:-default}

Check the parameter expansion section of the bash man page for more.

> Secondly, i have a script which looks like:
>
> someprog &
> someotherprog &
> quit() {
> shutdown-someprog
> shutdown-someotherprog
> }
> trap quit 0
> while read line; do echo -n ""; done
>
> The idea is that the script starts some other programs (actually ssh
> tunnels), then sits there doing nothing until someone sends it SIGINT or
> SIGQUIT (or sends EOF to its stdin) something, at which point it shuts
> then down cleanly.

someprog &
pid1=$!
someotherprog &
pid2=$!

quit() {
kill "$pid1" ## shutdown-someprog
kill "$pid2" ## shutdown-someotherprog
}

trap quit 0
while read line; do echo -n ""; done


> What's the best way to do the 'sit there doing nothing' part? I'm using a
> do-nothing read loop, but that's actually not much good, because as soon
> as background it, it stops (blocked on reading from a stdin which is no
> longer wired to a keyboard), and doesn't immediately respond to a SIGINT -
> i have to fg it before it dies. I thought about a 'sleep 999d', but that
> seems like no less of a kludge.
>
> Thirdly, the trap line is actually:
>
> trap 'echo -n ""; quit' 0
>
> Because if i set the trap action to just 'quit' (as shown above), it
> doesn't work. What gives?
>
> Thanks,
> tom
>
> [1] Part 5. VARIABLE SYNTAX of http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
>


--
Chris F.A. Johnson <http://cfajohnson.com>
Author: =======================
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
From: unruh on
On 2010-02-28, Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
> On 2010-02-28, Tom Anderson wrote:
>> Hi all,
>>
>> Firstly, i hear (from [1]) about a syntax that looks like $VARIABLE:t.
>> I've never come across that. Is this a csh thing, does bash have an
>> equivalent, and what does it do?
>
> I have no idea what that might mean in csh.
>
> In bash, it's a literal ':t' following whatever the variable
> expands to.

[unruh]>tcsh
{unruh}: set W=x
{unruh}: echo $W:t
x

From: Bruce Stephens on
"Chris F.A. Johnson" <cfajohnson(a)gmail.com> writes:

> On 2010-02-28, Tom Anderson wrote:

>> Firstly, i hear (from [1]) about a syntax that looks like $VARIABLE:t.
>> I've never come across that. Is this a csh thing, does bash have an
>> equivalent, and what does it do?
>
> I have no idea what that might mean in csh.
>
> In bash, it's a literal ':t' following whatever the variable
> expands to.
>
> In a Bourne-type shell, such as bash, there are various expansion
> involving braces, for example: ${x:-default}
>
> Check the parameter expansion section of the bash man page for more.

You might expect it to be there, but you'd be mistaken. Look instead
under history expansion (though I suspect it's almost always used on
parameters). It's like basename:

% a=foo/bar.baz
% echo $a:t
bar.baz

(I don't have csh or tcsh installed, the above is in zsh.)

[...]

From: unruh on
On 2010-02-28, Bruce Stephens <bruce+usenet(a)cenderis.demon.co.uk> wrote:
> "Chris F.A. Johnson" <cfajohnson(a)gmail.com> writes:
>
>> On 2010-02-28, Tom Anderson wrote:
>
>>> Firstly, i hear (from [1]) about a syntax that looks like $VARIABLE:t.
>>> I've never come across that. Is this a csh thing, does bash have an
>>> equivalent, and what does it do?
>>
>> I have no idea what that might mean in csh.
>>
>> In bash, it's a literal ':t' following whatever the variable
>> expands to.
>>
>> In a Bourne-type shell, such as bash, there are various expansion
>> involving braces, for example: ${x:-default}
>>
>> Check the parameter expansion section of the bash man page for more.
>
> You might expect it to be there, but you'd be mistaken. Look instead
> under history expansion (though I suspect it's almost always used on
> parameters). It's like basename:
>
> % a=foo/bar.baz
> % echo $a:t
> bar.baz
>
> (I don't have csh or tcsh installed, the above is in zsh.)

In tcsh
[unruh]>export a=/usr/local/bin/a.b
wormhole[unruh]>tcsh
[unruh ~]$ echo $a
/usr/local/bin/a.b
[unruh ~]$ echo $a:t
a.b
[unruh ~]$