-2

I have a variable var with value

backup = urls://string.abc.com

I want to exclude everything before = so that var has

urls://string.abc.com

I am using var | cut -d "=" but it is not giving correct result

meallhour
  • 11,517
  • 14
  • 47
  • 86
  • .. `awk '{print $3}'` ... – l'L'l Sep 06 '18 at 01:58
  • I believe the whitespace around the assignment of `backup = urls://string.abc.com` should result in failures; see [Command not found error in Bash variable assignment](https://stackoverflow.com/q/2268104/608639). Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), etc. – jww Sep 06 '18 at 02:17

1 Answers1

5

Use the Parameter Expansion operator:

var=${var/*=/} # Replace everything matching *= with empty string

or

var=${var#*=}  # Remove prefix matching *=

You can also do it with cut, but you need more code around it:

var=$(echo "$var" | cut -d= -f2-)
Barmar
  • 669,327
  • 51
  • 454
  • 560