Search code examples
linuxbashsedcut

Delete everything in string after "="


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


Solution

  • 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-)