Output from clasp list contains strange characters

112 Views Asked by At

I am building a script that gets the project name from the clasp and creates a directory. Everything is going fine but the directory is named weirdly.

This is what I am doing

Get the information regarding the project

info=$(clasp list)
declare -p info

output is \E[2K\E[1Gnotify-slack-from… – https://script.google.com/d/18S6ot_3uvqGNujti3XPqOTTQwxYUEnr_j0y2GMQcFvWStg5ZIyCPURiN/edit

Here is the output of clasp list | hexdump -C

00000000  1b 5b 32 4b 1b 5b 31 47  6e 6f 74 69 66 79 2d 73  |.[2K.[1Gnotify-s|
00000010  6c 61 63 6b 2d 66 72 6f  6d e2 80 a6 20 20 20 e2  |lack-from...   .|
00000020  80 93 20 68 74 74 70 73  3a 2f 2f 73 63 72 69 70  |.. https://scrip|
00000030  74 2e 67 6f 6f 67 6c 65  2e 63 6f 6d 2f 64 2f 31  |t.google.com/d/1|
00000040  38 53 36 6f 74 5f 33 75  76 71 47 4e 75 6a 74 69  |8S6ot_3uvqGNujti|
00000050  33 58 50 71 4f 54 54 51  77 78 59 55 45 6e 72 5f  |3XPqOTTQwxYUEnr_|
00000060  6a 30 79 32 47 4d 51 63  46 76 57 53 74 67 35 5a  |j0y2GMQcFvWStg5Z|
00000070  49 79 43 50 55 52 69 4e  2f 65 64 69 74 0a        |IyCPURiN/edit.|
0000007e

I dont want the strange characters at the start of the string.

After doing the above, I split the string into two at ' - ' using

projectname=(${info// - / })

After this, I create a directory using

mkdir $projectname

This creates a directory with name \033[2K\033[1Gnotify-slack-from… What I want is a directory with the name notify-slack-from…

Any idea what I may be doing wrong?

2

There are 2 best solutions below

0
On BEST ANSWER

Given that it appears to be a prefix of fixed size you want to remove, you can use

projectname=${projectname:8}

to trim the leading 8 bytes from the value.

0
On
pn=$(echo "${projectname}" | cut -d'G' -f2)

The above works, too.