Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How the home alias (~) is it expanded? Post 302986244 by Don Cragun on Tuesday 22nd of November 2016 03:09:29 PM
Old 11-22-2016
Quote:
Originally Posted by jcdole
Hello.

Shell : bash
Operating system : opensuse leap 42.2
Kate is KDE editor

Another example :
Code:
MY_PATH="~/bin/200_yast_install"
ls $MY_PATH
ls: cannot access '~/bin/200_yast_install': No such file or directory

When the tilde is quoted, it is a regular character and should not be expanded by the shell into your home directory. Therefore, the shell is behaving as expected for the above example.
Quote:
Code:
MY_PATH=~"/bin/200_yast_install"
ls $MY_PATH
ls: cannot access '~/bin/200_yast_install': No such file or directory

The tilde here still isn't required to be expanded because the / following the ~ is quoted.

Note, however, that the sequences of commands:
Code:
MY_PATH=~/"bin/200_yast_install"
ls "$MY_PATH"

Code:
MY_PATH="$HOME/bin/200_yast_install"
ls "$MY_PATH"

should do what you want to do. (Note the use of double-quotes around the expansion of MY_PATH in the ls command. Without the quotes there, any spaces that had been quoted when you assigned the string to MY_PATH will be parsed by the shell into separate arguments for ls.

Expanding on what RudiC said...
The above rules apply whenever a ~ expansion is performed. In an assignment statement (and only in an assignment statement), any ~ up through and including the next following colon or slash, if there is one in the current word, must be unquoted for ~ expansion to occur. This allows multiple ~s to be expanded when setting the PATH, CDPATH and similar variables. Note also that the general format of a ~ expansion is any one of the three forms: ~logname, ~logname/, and ~logname: which will expand to the login directory for the user named logname on your system (followed by a colon or slash, respectively, in the last two forms). As you already know, if you omit logname in any of these forms the ~ expands to the quoted expansion of $HOME. ~ expansions only occur when ~ is the first character in a word except for the cases stated above in assignment statements.

Quote:
I think is a " problem.

But if one have space in folder name, seems not to be able to use " with ~
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
All times are GMT -4. The time now is 08:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy