Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Command Line Fundamentals

You're reading from   Command Line Fundamentals Learn to use the Unix command-line tools and Bash shell scripting

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher
ISBN-13 9781789807769
Length 314 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Vivek Nagarajan Vivek Nagarajan
Author Profile Icon Vivek Nagarajan
Vivek Nagarajan
Arrow right icon
View More author details
Toc

Chapter 4: Shell Scripting

Activity 10: PGN Game Extractor Enhancement

The solutions are provided in five script files, pgn_extract_act1.sh to pgn_extract_act5.sh. Each script contains the changes made in the previous problem steps, so pgn_extract_act5.sh has all the issues that were mentioned previously addressed. The following are the possible solutions:

  1. The following code can work:
    function count_moves()
    {
      IFS='.'
      local moves_arr=( $moves )
      local second_last=${moves_arr[@]: -2 : 1}
      IFS=' '
      local second_last_arr=( $second_last )
    
      num_moves=${second_last_arr[@]: -1 : 1}
    }
  2. Detecting blank lines can be done by testing for an empty string, such as the following:
    [[ -z $line ]] && return 0
  3. Instead of expressions such as count=$(( count + 1 )), we can write (( count ++ )). We can also change the [[ ]] based conditionals, which test numeric variables such as [[ $should_print...
lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime