课程: Learning Linux Shell Scripting

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Reading files

Reading files

- [Instructor] We can read a file into a script using the read command and redirection. First, let's create a text file so we can read it later. Touch names.txt and atom names.txt Enter the following name or your own if you like. Place each name on it's own line. There is no need for a shebang since, this is a text file and not a script. So Abel, Maria, Richard, Tom, and Rene. Then we do a control S to save it and let's return to the terminal. Now let's create our script. We do touch reader.sh, change mode 755, reader.sh, and finally atom reader.sh Enter our shebang /bin/env space bash and we create a counter, so COUNT=1 and then we type in while IFS=, and these are single quotes with nothing in between them space read -r and LINE in all caps. IFS is the internal field separator. It tells Linux how to parse the field of the line we are reading. We aren't doing anything special so we don't really need this so we set it to an empty string. The -r on the read command says do not allow…

内容