Friday, September 18, 2020

Unwanted Dollar Sign in Bash Script

The script that I used ran fine for various flavors of Linux for a long time. But somehow, it produced unwanted dollar sign on Ubuntu 18.04, so my hours of troubleshooting starts.

Problem

The simplest one I can say is I use echo with tab and variables and piped that to awk through AWS Systems Manager. It is similar to the following:

v='variable'
TAB=$'\t'
echo "${v}${TAB}" | awk '{print $0}'

In many flavors of Linux other than Ubuntu 18.04, even in Ubuntu 16.04, it produced the expected result:

variable

However, in Ubuntu 18.04, it ends the result with an extra dollar sign:

variable$

At first, I thought it marks end of line or the typical \0 (NUL character) that marks end of string, so I tried various ways to remove it such as using tr, gsub, etc. But none of them works.

Solution

Eventually, I found out that the dollar sign comes from the TAB variable. To solve it, I have to replace the above with:

echo -e "${v}\t"

1 comment:

  1. If you are looking for using Windows 10 Fax and Scan multiple pages by flatbed scanners or printers, you should know that the Fax and Scan app built-in on Windows 10 computer is a very basic one.

    Scanning multiple pages into one document might seem tough if you do not know how to windows scanner multiple pages . If you are one of them who work with documents of many pages regularly, this post is going to help you.

    However, it is not very easy to do this work for free. There are a few paid tools that offer you this. In this article, I am going to talk about the tools you need to have to do it along with other tips on different scanners for scanning multiple pages into one PDF. Let’s get started.

    ReplyDelete