mbxzxz
mbxzxz

Reputation: 425

Bash delimit string without IFS

I have an email like [email protected]
and the output should be first_last

I tried delimiting on @ first and then replaced . with _
Is there an easier single line way to do it without using IFS?

Upvotes: 0

Views: 91

Answers (1)

choroba
choroba

Reputation: 241988

You can use parameter expansion:

#! /bin/bash
[email protected]
name=${email%@*}   # Remove everything after the last @.
name=${name//./_}  # Replace all dots by underscores.
echo "$name"

Upvotes: 1

Related Questions