views:

76

answers:

4

Hi all:

What is the syntax for specifying a dynamic profile name in linux command? E.g.

perl genhtml /home/$(usrProfile)/*

What is the syntax to replace usrProfile if it is dynamic?

Thanks.

EDIT: I'm running this in Windows Command line under cygwin.

UPDATE: I have tried doing the following:

$ECHO $HOME
chmod 444/home/~username/*

But I've gotten the error saying

No such file or directoryine 1: /home/Administrator
chmod: cannot access '/home/~username/*': No such file or directory

The only profile I have in the cygwin's home directory is Administrator so the directory exists physically.

My goal is to be able to call the above command without worrying profile name either directly in a build script (MsBuild), or via cygwin's bash command.

Thanks.

A: 

~/ at the beginning of a pathname specifies the current user's home directory. Use ~username/ to get a specific user's home directory instead.

Ignacio Vazquez-Abrams
A: 
$ user=somebody
$ echo ~$user
~somebody
$ eval echo ~$user
/home/somebody
$ getent passwd $user | cut -d: -f6
/home/somebody
$ ls $(getent passwd $user | cut -d: -f6)
...

This will work even if the user's home directory is set to something other than /home/$user.

ephemient
A: 

You want either backticks or $() notation.

perl genhtml /home/`program args`/*

perl gethtml /home/$(program args)/*

On recent versions of Bash, both of those run the program args, and substitutes the output of the program into the command line.

The backtick notation is the classic way to do this and will work on most shells. The $() is more recent (although I think it's been around for 10 years at this point). The $() notation is preferred because it is easier to nest - prog1 $(prog2 $(prog3))

R Samuel Klatchko
+1  A: 
$ echo $HOME
/home/username

Edit:

In your update, I'm assuming you're not typing the dollar sign before the echo. Also, I would use lowercase for commands, even though they work under Cygwin - they won't elsewhere. There needs to be a space after the permission setting. Plus, I doubt there's a tilde in the actual username. And are you really sure you want to blindly set all the files to the same permission? What if there are existing files?

echo $HOME
chmod 444 /home/username/*

What you probably really want to do is something more like:

chmod 444 "${HOME}"/your_app_dir/*

or

chmod 444 "${HOME}"/some_specific_file
Dennis Williamson
@Dennis: thanks for your concerns. I have full control over the files and its directory so setting the directory's access is not a problem. Cygwin only plays a very small role in the stuff I'm working on. I'm only using it to deal with permission setting and generating some stuff using perl so I don't think its going to have a huge impact on the application.
BeraCim