ramachandrajr has asked for the wisdom of the Perl Monks concerning the following question:

sorry if i shouldnt post bash questions in perl monks but its an easy one .when i write: input
echo --version
output
--version
input
code="\tcode" echo $code
output
tcode
instead of the version details and also \n\a\c\b\x are not working well right now i am reading shell scripting so is this book too old and amendments are made in shell script? or am i doing something wrong

Replies are listed 'Best First'.
Re: OT: unable to use the options of echo in my shell terminal bash ofcourse
by RichardK (Parson) on Sep 13, 2015 at 11:18 UTC

    Bash has it's own built-in version of echo, which is why you can't display the version.

    Reading the manual for bash you'll see that if you want to interpret backslash escaped characters you need to use the -e option.

    echo -e "\tcode"
      wow i am dumb,you are absolutely a time saver bro,i knew that all perl users use linux ;p
Re: OT: unable to use the options of echo in my shell terminal bash ofcourse
by Corion (Patriarch) on Sep 13, 2015 at 11:26 UTC

    Why don't you use Perl if echo is too complicated for you?

Re: OT: unable to use the options of echo in my shell terminal bash ofcourse
by NetWallah (Canon) on Sep 13, 2015 at 17:19 UTC
    Responding to the yet un-answered part of your OT query:
    You can get the BASH version by:
    $ echo $BASH_VERSION 4.2.25(1)-release # Just the Major version: echo $BASH_VERSINFO 4
    Another alternative:
    $ bash --version GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gp +l.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
    or even: (Ctrl-x Ctrl-v) , which shows
    GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)

            Software efficiency halves every 18 months, thus compensating for Moore's Law.

Re: OT: unable to use the options of echo in my shell terminal bash ofcourse
by choroba (Cardinal) on Sep 14, 2015 at 10:54 UTC
    "\tcode" doesn't mean anything special in bash. To turn \t into a tab character, you have to use $'\t':
    #! /bin/bash string=$'\tcode' echo "$string"
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      x\ty works as expected in zsh 4.3.10; does not in /bin/sh (FreeBSD ash) & bash 4.3.42 as shown above.

      Then again I much prefer to use the command (/usr/bin/)printf, NOT the shell built-in, unless just writing one-off script on the command line.

        thanks every one i learned a lot of things from u guys
      awesome i didn't even know that learned something today thank u