How the home alias (~) is it expanded?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How the home alias (~) is it expanded?
# 8  
Old 11-22-2016
Quote:
Originally Posted by bakunin
I might be overly paranoid here, but using unquoted strings in shell scripts is asking for trouble. In this case the trouble would be that a home directory has a space char in it (which is very ill advised to do in first place, but if i would have gotten a penny for every idiotic decision i have seen on a system during my career i'd be stinking rich).

... ... ...
I agree that having <space>, <tab>, or especially <newline> in a directory (or any file) name is a bad idea. But, if the pathname in the variable HOME (for ~ expansions) or if a user's home directory in the system's user database (/etc/passwd on many systems) (for ~logname expansions) contains spaces, periods, question marks, asterisks, square brackets, parentheses, or other characters that could cause field splitting or pathname expansions, tilde expansions should still work. The standards explicitly state:
Quote:
The pathname resulting from tilde expansion shall be treated as if quoted to prevent it being altered by field splitting and pathname expansion.
But, of course, if a variable is set to something containing a tilde expansion, expansions of that variable still need to be quoted. If some idiot sets up a login directory named /home/my directory, login procedures will set:
Code:
HOME="/home/my directory"

for that poor user, but the command:
Code:
MY_UTILITY=~/"bin/my utility"

will set MY_UTILITY to the string /home/my directory/my utility. Having done that you can execute that utility with:
Code:
"$MY_UTILITY"

but trying to execute it with:
Code:
$MY_UTILITY

will attempt to run the command /home/my with arguments directory/my and utility (assuming default IFS settings).
# 9  
Old 11-22-2016
As my question was how to quote string path when using ~ , thank you very much every body for helping
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Wild char getting expanded in echo

Hi All, I am having a issue in a script. I am trying to execute a select * from a scirpt to a database and printing the the sql string. The * in the sqltring is printing all the files in the directory. How to handle it ? .. .. sql="select * from emp" execute ($sql) echo $sql Here my... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

2. Solaris

zpool hasn't expanded

Hi Guys, I have a raidz zpool that consists of four disks. 2x2TB, 1x1TB and 1x0.75TB. Originally it was only 1x1TB, 3x0.75TB, and I had around 1.7TB of storage capacity. I've just switched out two of the 0.75TB disks for the 2x2TB ones. I did this one at a time and now the resilvering is... (2 Replies)
Discussion started by: rudigarude
2 Replies

3. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

4. Shell Programming and Scripting

cp -p /home/* home/exp/*.date not working please help

:( ---------- Post updated at 01:51 AM ---------- Previous update was at 01:50 AM ---------- Not working ---------- Post updated at 02:04 AM ---------- Previous update was at 01:51 AM ---------- cp -p /home/* home/exp/*.`date` i am using this (4 Replies)
Discussion started by: rishiraaz
4 Replies

5. Solaris

war file not expanded (tomcat solaris)

hi .. my example.war file is not expanded in the webapps folder.. could u guide me why the file is not expanded when i restart tomcat... (1 Reply)
Discussion started by: senkerth
1 Replies

6. Shell Programming and Scripting

List file with variables expanded

Hello, I have this problem. I have script file, e.g. #!/usr/bin/ksh echo $MY_DIR ls -lt $MY_DIR I want to list the script but with MY_DIR variable expanded. E.g. MY_DIR=/abc/xyz (in shell MY_DIR is set) So I want to list the script and see: #!/usr/bin/ksh echo /abc/xyz ls... (6 Replies)
Discussion started by: r1omen
6 Replies

7. UNIX for Advanced & Expert Users

Redirect contained in variable not expanded as expected

Hi all, I have a selection of files that contain several commands that write to a file and are started as background processes similar to below. command_to_run_simulator -simulator_arguments > log_file 2>&1 & command_to_run_simulator -simulator_arguments > log_file 2>&1 &... (2 Replies)
Discussion started by: noose
2 Replies

8. Programming

Macros expanded output of c files

Hi, I want to just expand the macros in a set of c files from a filelist which are in different directories. I don't want the header files included in the c file to be expanded. I have a perl script which does gcc -E <infile> -I <path to search for header files> -imacros <infile> But in... (1 Reply)
Discussion started by: spsenthil
1 Replies
Login or Register to Ask a Question