Linux Bash script read through file tab delimited

This bash file will create hard links from a tab delimited text file that declares on each row the source and hard link destination

To run such a bash file:
Create a new document.
What ever name, end in .sh
Right-click, select properties/ make executable change permissions if needed
Always start such a file with #!/bin/bash
To run the file type: sh dir/file.sh

#!/bin/bash

# Opens a text file, reads each line
#     Each line in the text file has two items separated by tab
#     First item is the SourceFile (SF)
#     Second item is the destination folder and name to put the hard link (DL)
# Creates a hard link with line's parameters
# read -r, the -r says to not allow backslashes to escape any characters
#     http://linuxcommand.org/lc3_pages/readh.html

filename='/media/Office-Files/Files/create_links.log'     # variable to set text file.
IFS="    "                                      # set read to separate with tabs (between double quotes is an actual tab from the keyboard).
while read -r SF DL ; do                      # read each line in the text file and assign variable to each item.
    ln  "$SF" "$DL"  2>> errors.txt                        # create hard link using variables from text file.

done < "$filename"                          # strange that the text file name is put at the end, but it is.

Comments are closed.