I would like to know how I can print the string I have but without having the last two characters in bash. for example:
str = "hello.c"
And then print only hello
Thank for answers.
I would like to know how I can print the string I have but without having the last two characters in bash. for example:
str = "hello.c"
And then print only hello
Thank for answers.
The answer is to use bash-builtin string manipulation:
str="hello.c"
echo "${str%.c}"
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the '
%
' case) or the longest matching pattern (the '%%
' case) deleted. If parameter is '@
' or '*
', the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with '@
' or '*
', the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.