How to Open Two Files in a Shell Script
A shell script is a program written in one of the Linux/Unix shell languages. One of the most widely used shell languages is Bash. Bash allows you to use both Unix commands and Bash commands to interact with the operating system. The script is written in plain text form, and is executed from the command line. To open two text files, you can use any text editor such as Vim (a command line editor) or Gedit (a graphical editor). Either editor can be called from within a Bash script.
Instructions
-
Vim
-
1
Open a blank document in a text editor.
-
2
Type the line "#!/bin/bash" to begin your shell script.
-
-
3
Type the line "vim -p file1.txt file2.txt" to open the files. When the script is run, it will open the files in separate tabs in a terminal window.
-
4
Save the file as "open2files.sh".
-
5
Open a terminal window to test the script.
-
6
Navigate to the directory where you saved your script.
-
7
Type the command "chmod +x" to make the script executable.
-
8
Type the command "./open2files.sh" to run the script.
-
9
Switch between the tabs by typing ":tabn" in the Vim editor.
Gedit
-
10
Open a blank document in a text editor.
-
11
Type the line "#!/bin/bash" to begin your shell script.
-
12
Type the line "gedit file1 file2" to open the two files in the separate tabs.
-
13
Save the file as "open2files.sh".
-
14
Open a terminal window to test the script.
-
15
Navigate to the directory where you saved your script.
-
16
Type the command "chmod +x" to make the script executable.
-
17
Type the command "./open2files.sh" to run the script.
-
1