Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Command Line Fundamentals
  • Table Of Contents Toc
Command Line Fundamentals

Command Line Fundamentals

By : Vivek Nagarajan
close
close
Command Line Fundamentals

Command Line Fundamentals

By: Vivek Nagarajan

Overview of this book

The most basic interface to a computer—the command line—remains the most flexible and powerful way of processing data and performing and automating various day-to-day tasks. Command Line Fundamentals begins by exploring the basics, and then focuses on the most common tool, the Bash shell (which is standard on all Linux and iOS systems). As you make your way through the book, you'll explore the traditional Unix command-line programs as implemented by the GNU project. You'll also learn to use redirection and pipelines to assemble these programs to solve complex problems. By the end of this book, you'll have explored the basics of shell scripting, allowing you to easily and quickly automate tasks.
Table of Contents (6 chapters)
close
close

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...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Command Line Fundamentals
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon