Linux: Bash String Ends With...
In this article, we are going to check and see if a bash string ends with a specific word or string. This is quite a crucial action for most advanced users. Also, at the end of this post, we will share how you can access Linux partitions and view your Linux files on a Windows PC.
Here you will find out:
- how to check if a bash string ends with a specific word
- how to define the last character in bash strings
- when DiskInternals can help you
Are you ready? Let's read!
How to check if a bash string ends with a specific word
Using the example below, we will try to validate if a bash string ends with a specific word/string. The string is “testing”, and we are trying to ascertain if the string ends with “ing”.
You can copy the code above and save it as “test.sh”, then use the following command to run the script:
The output will be:
How to define the last character
You can use the command to find stings in another string. If you have a string that does not end with “/”, you can use grep to get its last character. The example below shows how to achieve this.
From the code above, “$?” denotes the exit status, and the –q flag is needed in case the argument turns true, and nothing is printed. If the match was found, the exit status would be 0. The –E flag allows regex matching, while the "/$" represents the end of the string.
Different ways of using regex match operators
There are quite different ways of using the regex match operator (=~), and here are the most common ways.
Method 1:
The following syntax is what to use to check and see if a string begins with a word or character.
Note: The most recent versions of bash (v3+) support the regex comparison operator “=~”.
To match this or that in a regex, use “|”.
Example:
user* means “use” and zero-or-more occurrences of “r”; thus, “use” and “userrr” is supported.
user.* means “user” and zero-or-more occurrences of any character; thus, “user1” or “userX” is supported.
^user.* means to match the pattern user.* at the beginning of $HOST.
Note: the expression above is a “proper” regular expression syntax.
The syntax below will check to see if $var starts with the hashtag:
Method 2:
To see if a string contains a substring, use the following syntax:
Note: the full stop (.) that comes before the asterisk (*) matches zero or more occurrences of any character that is not a newline character.
Output:
It's there.
Finally, it is important to note that the regex match operator “=~” won’t work when you use single square brackets; you must double the square brackets.
So, is it possible to open Linux files from Windows or not?
Of course, it is very possible to open Linux files on Windows.




All you need is DiskInternals Linux Reader, a freeware app with a distinctive interface that is very easy to understand and navigate. DiskInternals Linux Reader works perfectly for users on a dual-boot PC or virtual machine. With the help of this software, you can easily access Linux partitions on Windows PC and view the files that are saved inside.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command
