help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] handling variables with tilde character


From: kai
Subject: [Help-bash] handling variables with tilde character
Date: Tue, 03 Jul 2012 23:48:33 +0400
User-agent: Roundcube Webmail/0.5.2

Hello,

i'm experiencing some strange bash behaviour with tilde char in front of variables. Take a look at this example:

22:28:32||/home/kai-> mv .ssh .sshbackup
22:29:33||/home/kai-> rm -rf .ssh
22:29:35||/home/kai-> ls -la .ssh
ls: cannot access .ssh: No such file or directory
22:29:37||/home/kai-> mkdir ~kai/.ssh
22:29:39||/home/kai-> ls -la .ssh
total 28
drwxr-xr-x 2 kai users 4096 Jul 3 22:29 .
drwxr-xr-x 81 kai users 20480 Jul 3 22:29 ..

^^^^ everything is ok, let's use username as variable:

22:29:41||/home/kai-> rm -rf .ssh
22:29:44||/home/kai-> ls -la .ssh
ls: cannot access .ssh: No such file or directory
22:29:45||/home/kai-> user="kai"; mkdir ~$user/.ssh
mkdir: cannot create directory `~kai/.ssh': File exists
22:29:48||/home/kai-> ls -la .ssh
ls: cannot access .ssh: No such file or directory

^^^^ there is that strange behaviour. let's wrap variable in quotes:

22:30:21||/home/kai-> user="kai"; mkdir ~"$user"/.ssh
mkdir: cannot create directory `~kai/.ssh': File exists
22:30:32||/home/kai-> ls -la .ssh
ls: cannot access .ssh: No such file or directory
22:30:34||/home/kai-> user="kai"; mkdir '~'"${user}"'/.ssh'
mkdir: cannot create directory `~kai/.ssh': File exists
22:30:55||/home/kai-> ls -la .ssh
ls: cannot access .ssh: No such file or directory

^^^^ same issue. what i'm doing wrong?

i'm using opensuse 12.1 distro with bash version 4.2.10(1)-release (x86_64-suse-linux-gnu) and bash-completion package version 1.3-3.1.1.


Cheers,

Kai



reply via email to

[Prev in Thread] Current Thread [Next in Thread]