(Using Bash 4.4)
When I write something like
then I get the message that the directory '~/docs' does not exist. I understand that the tilde is not expanded at the time of the above assignment because of the quotes. But why is it not expanded at the time when the ls command is executed?
I also understand that at that time tilde expansion occurs before parameter expansion. But isn't the tilde available for extension at that time? After the initial assignment dir has the value ~docs.
Then at the time of executing
that should be the same as writing
.What am I missing?
(Using Bash 4.4)
When I write something like
then I get the message that the directory '~/docs' does not exist. I understand that the tilde is not expanded at the time of the above assignment because of the quotes. But why is it not expanded at the time when the ls command is executed?
I also understand that at that time tilde expansion occurs before parameter expansion. But isn't the tilde available for extension at that time? After the initial assignment dir has the value ~docs.
Then at the time of executing
that should be the same as writing
.What am I missing?
Please carefully proofread your posts before you hit the submit button. Like the shells you will be using, the people who read this forum and try to help you with problems you're having tend to read code VERY literally. So, if you start out with:
there is absolutely no way that the command:
is going to produce the output:
Instead of that output, it is going to produce the output:
Quote:
~/dox
If we can't run the code you show us and get the same output you say you're getting, it raises all sorts of questions that can waste a lot of time for everyone involved.
Moving on to your other questions...
As you said tilde expansion is performed before parameter expansion (and it is performed by the shell, not by the kernel and not by all of the utilities {such as ls} that you ask the shell to invoke for you). So, if parameter expansion produces output containing a tilde, that tilde won't be expanded.
Note that although ls doesn't perform tilde expansion, there are some commands that you can invoke in the shell that will perform tilde and other expansions. These include, but are not limited to, invoking another shell or invoking eval.
So, to get what you seem to want to do you can use any of the following (and hundreds of other possibilities):
This User Gave Thanks to Don Cragun For This Post:
I'm sorry for the typo. You're right, the output of the command is ~/docs. I probably should have copy/pasted from the terminal but I extracted the problem from a more complex piece of code and the error occurred during that transcription.
Hello All,
Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion.
Let's say I have following variable.
path="/var/talend/nat/cdc"
Now to get only nat I could do following.
path1="${path%/*}"
path1="${path1##*/}"
Here... (8 Replies)
Hi
I have a script that it sends emails to various recipients using mailx, but some of the recipients should be sent as BCC, but ~b flag when used in the following line, does not put the gmail address as BCC:
echo "node $output is down" | mailx -s "$output not pinging" sadf@xyz.com ~b... (8 Replies)
Hi,
Below script used for sftp get,
#/bin/bash
USER=xxx
PASS=xxx
HOST=xxx
REMOTE_FILE=$1
LOCAL_FILE_LOC=$2
cd $LOCAL_FILE_LOC
lftp sftp://$USER:$PASS@$HOST:10022 -e "get $REMOTE_FILE; bye"
If file does not exist in sftp server, and file (same as remote file name) exists in local dir,... (4 Replies)
I am trying to find the home directory of users on a UNIX (Solaris/AIX) box using
echo ~usernameThis does return the home directory for all valid users. For some reason this command also outputs home directory which are non-existent for few users who seem not to have logon access to that... (31 Replies)
Does anyone know of a reliable method to disable tilde expansion while a script is running and then re-enable it when the script is done?
I often have to work with files that have sections like this in them:
555 ~~~~~~~~~~ AN:AutoAttendant~~~~~~~~~~~~
9195551212 ~~~~~ ... (1 Reply)
Hi ,
could anyone help me out with this problem.
sample.txt has this content :
u001- this is used for project1 ||
u002- this is used for p2|| not to be printed
u003- this is used
for project3 ||
u004- this is
used for p4 ||
u005- this is used for project5 ||
u006- this is used for p6... (9 Replies)
Hey folks,
I have used gVim in Windows for many years but I have never found an answer to a very simple question I am going to ask you guys...
My question is if there is a way to eliminate the creation of those ~ files that gVim creates in Windows. If you have ever used gVim in Windows you... (2 Replies)
Hi All,
I want to delete duplicate records from a tilde delimited file. Criteria is considering the first 2 fields, the combination of which has to be unique, below is a sample of records in the input file
1620000010338~2446694087~0~20061130220000~A00BCC1CT... (5 Replies)
i have a file in unix in which datas are like this
07 01 abc data entry Z3 data entry ASSISTANT Z3 39
08 01 POD peadiatrist Z4 POD PeDIATRY Z4 67
01 operator specialist 00 operator UNSPECIFIED A0 00
... (12 Replies)
hello all,
i have a comma delimited file.
i want to replace the commas in the file with the tilde symbol using sed.
how can i do this?
thanks. (4 Replies)