0

I use Cent OS 7, and have written a Bash script.

I tried to get the length of variable:

#!/bin/bash
URL_STRING="1";
VAR_LENGTH=${#URL_STRING}
echo $VAR_LENGTH;

But I get syntax error

SLePort
  • 15,211
  • 3
  • 34
  • 44
MisterPi
  • 1,471
  • 5
  • 17
  • 23
  • 1
    Where is URL_STRING set? Also probz best not to use uppercase variable names as they are typically used for env variables. – 123 Nov 17 '16 at 09:12
  • 1
    What error did you get? – Inian Nov 17 '16 at 09:12
  • 1
    Are you really in bash? What exact error do you get? It is a valid syntax you are using, so nothing should happen – fedorqui Nov 17 '16 at 09:22
  • 1
    This is valid posix shell syntax. It works quite fine. Here's a link to the Single Unix Specification stating what should be supported: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 – John Szakmeister Nov 17 '16 at 09:34

1 Answers1

0

Try this code

echo $URL_STRING| awk '{printf("%d",length($0))}' | read asd

infotoni91
  • 722
  • 3
  • 13