0

I am presently writing a shell function and it would help me in writing it to be able to remove a . from the start of a folder name (changing the folder name from that of a hidden folder to that of a non-hidden folder). The folder name is stored in the variable $CWD, which itself is evaluated using:

CWD=${PWD##*/}

I would like to call the variable that equals $CWD without the . at its start $GWD. Presently I am trying to do this using sed, but I am open to any solution to this problem. This is what I have been trying:

GWD=$(sed -i 's/.*//' $CWD)

I have also tried substituting ' in this expression with " and I have tried substituting -i with -e. But this keeps returning the error:

sed: can't read .atom: No such file or directory

where CWD='.atom' for me at the moment.

Josh Pinto
  • 3,493

1 Answers1

3

GWD="${CWD#.}"

Your sed command didn't work because it wanted to read the file defined in $CWD. You would have wanted to echo $CWD | sed 's/^[\.]//'

You might also be interested in this other question which will help you get CWD more robustly.