shell script queries: $home; broadcast ping

Dear all,

This is the Bionic Fysh again. I have two quick questions:

1- when writing shell scripts, how does one allow the tilda ~ into the script ?
e.g
ls ~;
ls ~me;
user=you;
ls ~$user (N.B I think that for this one you need: ls `~$user`)

2- In FreeBSD 4.0, I would like for a normal (wheel) user to ping
by default, only the root can ping. And I would like to send a broadcast ping (like ping -b in linux) to a subnet.
e.g ping -b 192.168.1.0

Many thanks in advance,

Da Bionic 1
:wink:

I'm not completely sure what you mean. The tilde should work find just as is:

ls ~      # lists your home directory
ls ~me    # looks for a directory called ~me
          # if me is your username, also lists your home dir
user=you  #
ls ~$user # will try to list the home directory of
          # someone with a login name of 'you'

Not sure about the second question...

1.'~' in the shell

ls ~ # lists your home directory
ls ~me # will try to list the home directory of someone with a login name of 'me'
user=you
ls ~$user # will try to list the home directory of someone with a login name of 'you'
ls ~/MyDir # will try to list the 'MyDir' directory (or file) of my $HOME directory
ls ~root/bin # will list the 'bin' directory of '/' (becouse '/' is $HOME directory for the root)

PS:
in all the constructions '~' have to be very first character to get proper shell expansion
look at the 'Directory Substitution' under man for shell

  1. ping question

Find location of the ping command ('which ping' or 'type ping' depending on your shell).
Examine directory attributes of the 'ping' location ( 'ls -l directoryname`)
If this directory is not readable or not executable by the 'world',
then copy ping to the common location ( 'usr/bin' )

Hi guys,

very sorry but I tried your recommendations, and this is what I get:

in script: myscript

ls ~
ls ~root
user=you
ls ~$user

OUTPUT
~: Ce fichier ou ce r�pertoire n'existe pas
~: This file or directory does not exit

~root: Ce fichier ou ce r�pertoire n'existe pas
~:root: This file or directory does not exit

~you: Ce fichier ou ce r�pertoire n'existe pas
~you: This file or directory does not exit

Thanks for any pointers

N.B thanks for the ping trick... now my users can ping without doing su - ...!
does anyone know how to do a 'broadcast ping'
e.g ping 192.168.1.0

returns something like:
found 192.168.1.1
found 192.168.1.2
found 192.168.1.3
found 192.168.1.4
etc....

Da Bionic 1
:slight_smile:

I'm not sure what's wrong.. I use Sco, but FreeBSD also uses the "~" to point to your home directory..

Until someone can help you out more or you figure out the problem, try this:

ls $HOME
user=xxx
ls $HOME/../$user

The first line is equivalent to ls ~

The last line will attempt to list some other user's directory, assuming all user directories are listed within the same directory.

Of course, if your account is root, then all other users will probably be somewhere beneath you, e.g. like /usr/home/xxx, so you can use ls /usr/home/$user

Dear all,

Thanks so much for the feedback.
I have tried the following:

vi new

ls $HOME
ls ~
ls ~toto

they all respond accordingly

however:

user=toto
ls ~$user

it returns: can't ls to ~toto (???)

so the script can find ~sos10
and can view the variable user as a character variable
...
but cannot work with both...

I hear that this is not possible in bash...
and may be possible in csh, tcsh, or maybe sh

but I always thought that when you do sh script
it would run it in pure sh ...?

cheers again for any comments

N.B please try this exactly:
user=toto
echo~$user

bionic fysh

The shell expands stuff like ~toto into a directory name early in its processing of a command line. And it expand $user fairly late.

Try this:

eval "ls ~$user"