![]() As the variable value contains the path that specifies the file path, it displays that the “$v is a file”. The output is as same as we have expected. Therefore, we have used the “bash” query with the file name mentioned within it. If the path contains a file, it will print that “$v is a file” otherwise, the “else” part echo statement will compile at the terminal.Īfter the code has been saved, this is a time to compile the bash script via a bash query. Within the “if” part of this statement, the condition has been used to check whether the variable path “v” contains a file or not via the “-f” flag. Within the “else” part, there is another “if-else” statement mentioned. If the condition meets, it will print “$v is a directory” otherwise, the other part of a statement will be compiled. ![]() So, within the first, if statement, we have mentioned a condition to check whether the variable value is a directory via the “-d” flag. Moreover, the nested “if-else” statement has been utilized properly to check whether the path of a variable is a file or a directory. Added the bash extension and initialized a variable v1, containing a file path as its value. Hence, we can say that the “else” part must have been executed his time.Īfter opening the bash document, we have written the below-shown bash script within it. The output for this instruction shows that the path mentioned in the file is specifying a file. Therefore, we have used the bash instruction in our console with the file’s name to check out the output. Now the time is to execute the bash file “test.sh”. After saving this bash code, we will be back to the console via “ Ctrl+S” and “ Ctrl+X” consecutively. The “fi” states that the “if” statement has been ended here. Otherwise, it will be executing the else part of the “if” statement and displaying “$v1 is a file” at the shell terminal. If the condition meets, it will execute the “then” part and display “$v1 is a directory”. It will check whether the mentioned variable value is a directory or something else. Inside the braces, we have to use the flag of “-d” representing the directory within its condition part. It is clear from the path that it indicates some bash files. We have declared a new variable “v1” and assigned it a “path” of a file as its value. ![]() ![]() Firstly, add the bash extension in the file as “#!/bin/bash”. To interact with the terminal, type bash and then press enter.The file has been launched in an editor. For bash, get the current directory in Linux Mint 20, open up the Terminal from the main menu on the bottom left of your screen, and then select the Terminal option. We have declared a new variable v1 and assigned it a path of a file as its value. The tutorial assumes that users already have the latest Linux Mint OS on their computer systems. Firstly, add the bash extension in the file as /bin/bash. User account: A user account with sudo rights Recommended OS: Linux Mint 20 or Ubuntu 20.04 Requirementsįollowing system requirements are mandatory to run the commands in the bash to get directory: The command used for accessing the current working directory will help them access any location in their system anytime, as per their requirements. In this tutorial, we will dig deep into the ways of accessing the current working directory and how users can switch from one directory or location to another, followed by relevant examples. The achieved output is standard and printed to the shell prompt. The Linux system responds by providing information against each input request. There are multiple options, and each time users interact with the command prompt of the current directory they are working. Users can access each directory through the terminal, and interact with them. There are different types of directories in a computer system with Linux or Ubuntu OS. In Linux, all tasks done through the command line require users to access adequate directories.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |