Using tilda can be very tricky... Yes " will make the substitution fail.. the same goes for /~ but there is nothing stopping you to use " after the tild e.g.
Shell : bash
Operating system : opensuse leap 42.2
Kate is KDE editor
Another example :
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:
The tilde here still isn't required to be expanded because the / following the ~ is quoted.
Note, however, that the sequences of commands:
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 ~
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).
Here is an alternative approach: the file /etc/passwd contains the user names as well as the home directories and it is world readable. Its format is colon-separated fields forming records separated by newlines. The home directory is the fifth field, the user name the first. Hence:
Similar with every other user attributes (primary group, login shell, ...).
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)
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)
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)
:(
---------- 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)
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)
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)
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)