{"id":9138,"date":"2015-03-21T20:15:48","date_gmt":"2015-03-21T20:15:48","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=9138"},"modified":"2015-03-21T20:15:48","modified_gmt":"2015-03-21T20:15:48","slug":"java-scanner-linux-test-run-dollar-sign-command-line-arguments","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/java-scanner-linux-test-run-dollar-sign-command-line-arguments\/","title":{"rendered":"Java Scanner Linux test run:  dollar sign command line arguments"},"content":{"rendered":"<h1>The tutor suggests an explanation for the surprise during the Linux test run.<\/h1>\n<p>&nbsp;<br \/>\nIn my <a href=\"?p=9117\">previous article<\/a> I reported a surprising finding of how my Java Scanner program reads dollar sign input from the <strong>bash<\/strong> command line.<\/p>\n<p>Pursuant to that issue, I&#8217;ll show another command line call and its result:<\/p>\n<p><code>java TryScanner $0.45 $125.27 $$1.28 \\$56.39<\/code><\/p>\n<p>The result:<br \/>\n<code><br \/>\nNot a readable number: bash.45<br \/>\nReadable number: 25.27<br \/>\nReadable number:22821.28<br \/>\nNot a readable number: $56.39<br \/>\n<\/code><\/p>\n<p><u>(Possible) explanation of first result:<\/u><\/p>\n<p>In <strong>bash<\/strong>, <code>$0 <\/code>is the command to tell what shell you are using (ie, <strong>bash<\/strong>).  Bash substitutes <strong>bash<\/strong> for <code>$0<\/code> in <code>$0.45<\/code>, giving <code>bash.45<\/code>.  <code>TryScanner<\/code> then reads <code>bash.45<\/code> and deems it not a readable number, since it contains non-numeric characters.<\/p>\n<p><u>(Possible) explanation of second result:<\/u><\/p>\n<p><code>$1<\/code>, in <strong>bash<\/strong>, means the first command line argument given to a <strong>bash<\/strong> script.  Since <code>java TryScanner<\/code> isn&#8217;t a <strong>bash<\/strong> script, <code>$1<\/code> points to a blank value.  Therefore, in place of <code>$1<\/code>, <strong>bash<\/strong> substitutes a blank.  The blank is just whitespace, so it doesn&#8217;t pollute the remaining <code>25.27<\/code>, which <code>TryScanner<\/code> finds and reports as a readable number.<\/p>\n<p><u>(Possible) explanation of third result:<\/u><\/p>\n<p><code>$$<\/code>, in <strong>bash<\/strong>, is the command to get the process id (pid) of the terminal.  In this case, it&#8217;s obviously <code>2282<\/code>, which is substituted (by <strong>bash<\/strong>) in front of <code>1.28<\/code>.  The resulting number <code>22821.28<\/code> is read and reported by <code>TryScanner<\/code> as a readable number.<\/p>\n<p><u>(Possible) explanation of the fourth result:<\/u><\/p>\n<p>In Perl, Java, and (it appears) <strong>bash<\/strong> as well, the backspace <code>\\<\/code> can be used to &#8220;escape&#8221; other characters.  When you escape a character, you change its meaning.  We know that the dollar sign <code>$<\/code> has special meaning in <strong>bash<\/strong>; apparently the <code>\\<\/code> in front changes it to just a regular character.  <strong>Bash<\/strong> hands <code>$56.39<\/code> to <code>TryScanner<\/code>, which, seeing the dollar sign in front, deems <code>$56.39<\/code> not a readable number.<\/p>\n<p>While, for the time being, I&#8217;d say we&#8217;re finished talking about the Java Scanner example, this post has opened up other topics for the future.  HIH:)<\/p>\n<p>I used many helpful sources for this post:<\/p>\n<p><a href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl tutorial<\/a><\/p>\n<p><a href=\"http:\/\/linuxsig.org\/files\/bash_scripting.html\">linuxsig.org bash scripting<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/21063765\/get-pid-in-shell-bash\">stackoverflow.com<\/a><\/p>\n<p>Kurniawan, Budi.  <em>Java 5:  A Beginner&#8217;s Tutorial<\/em>.  2006:  Brainy Software Corp.<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor suggests an explanation for the surprise during the Linux test run. &nbsp; In my previous article I reported a surprising finding of how my Java Scanner program reads dollar sign input from the bash command line. Pursuant to &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/java-scanner-linux-test-run-dollar-sign-command-line-arguments\/\"> <span class=\"screen-reader-text\">Java Scanner Linux test run:  dollar sign command line arguments<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[622,619,620,616,617,618,623,602,612,613,621,611,615],"class_list":["post-9138","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-in-bash","tag-0-in-bash","tag-1-in-bash","tag-bash","tag-dollar-sign-in-bash","tag-double-dollar-sign-in-bash","tag-escape-character","tag-java-programming","tag-java-scanner-example-on-linux","tag-java-scanner-example-ubuntu-bash","tag-java-scanner-test-program","tag-java-scanner-testing","tag-escape"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=9138"}],"version-history":[{"count":31,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9138\/revisions"}],"predecessor-version":[{"id":9169,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9138\/revisions\/9169"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=9138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=9138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=9138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}