HOWTO · Bash
How to Remove First Character From String in Bash
Learn three ways to remove the first character from a string in Bash, including native parameter expansion, sed, and cut.
On this page
Use Bash parameter expansion to remove the first character from a variable: ${my_string:1} takes the substring starting at offset 1. For example, applying it to Hello produces ello. Bash has no dedicated string-removal function, but this native expression handles the task without an external command. You can also use sed or cut when working with lines of text.
Remove the First Character With the sed Command
The sed substitution s/^.// removes the first character from each input line. In the pattern, ^ marks the start of a line and . matches one character. This is useful when processing line-oriented input; it does not treat a multiline value as one single string.
Run this example:
my_string="Welcome"
new_string=$(printf '%s\n' "$my_string" | sed 's/^.//')
printf 'The modified string is: %s\n' "$new_string"
The modified string is: elcome
Command substitution removes trailing newline characters from the command’s output. If preserving line boundaries or trailing newlines matters, account for that behavior when capturing the result.
Remove the First Character With the cut Command
The cut -c 2- option selects character positions starting at 2 and continuing through the end of each line. It therefore removes the first character per line, rather than slicing a multiline value as a single string. Use it for line-oriented text when that behavior matches your input. Character positions here are not byte offsets, so the command is intended for ordinary text rather than arbitrary binary data. Because cut reads standard input, it also fits pipelines where text is already arriving one line at a time.
For a single line, assign the result to a variable and print it. This example runs cut on the value and captures its result:
my_string="Hello"
new_string=$(printf '%s\n' "$my_string" | cut -c 2-)
printf 'The modified string is: %s\n' "$new_string"
The modified string is: ello
As with the sed example, command substitution strips trailing newlines from captured output. The cut utility is external to Bash, so this approach is most appropriate when you already need character selection from input lines.
Remove the First Character With Bash Parameter Expansion
Bash parameter expansion is the concise choice when the value is already stored in a Bash variable. The expression ${my_string:1} extracts the substring from zero-based offset 1 through the end; the first character is at offset 0. It does not launch sed or cut.
Run this example with a Bash variable:
my_string="Hello"
new_string=${my_string:1}
printf 'The modified string is: %s\n' "$new_string"
The modified string is: ello
For an empty or one-character value, ${my_string:1} yields an empty string. The expression operates on the variable value, so it does not remove trailing newline characters as command substitution does. For a value already held in a variable, it keeps the operation within Bash and makes the offset easy to adjust if you later need to remove more leading characters. Choose parameter expansion for a Bash variable, and choose sed or cut when you want to transform each input line. In short, match the tool to the shape of the input: use the native expression for one variable, and use a line-oriented command for a stream of records.