Đạt Michio
New member
How do you remove the first and last character of a string in Linux?
Answer
To remove the first and last character of a string, we can use the
parameter expansion syntax ${str:1:-1} in the bash shell. 1 represents the second character index (included). -1 represents the last character index (excluded). It means slicing starts from index 1 and ends before index -1 .
Answer
To remove the first and last character of a string, we can use the
parameter expansion syntax ${str:1:-1} in the bash shell. 1 represents the second character index (included). -1 represents the last character index (excluded). It means slicing starts from index 1 and ends before index -1 .