LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2016, 09:36 PM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Rep: Reputation: Disabled
tab space issue in script


hi,

output format is getting different one with wrong tab space alignment. even i ve checked with the tab spaces. need solution for the same.

[root@server ~]# cat variables
#!/bin/bash
echo "File Name : $0"
echo "First Argument : $1"
echo "Second Argument : $2"
echo "Quoted Values : $*"
echo "Total Number of Arguments : $#"
echo "PID of the scipt : $$"
echo "PID of last background process : $!"

[root@server ~]# sh variables arun akash
File Name : variables
First Argument : arun
Second Argument : akash
Quoted Values : arun akash
Total Number of Arguments : 2
PID of the scipt : 3802
PID of last background process :
[root@server ~]#
 
Old 04-17-2016, 10:34 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,328

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Since posting without using [CODE] ... [/CODE] tags did not preserve your tabs, it's a bit hard to see what you are trying to do. I presume you want those arguments all aligned regardless of the length of the label. Doing that with echo is going to be difficult. Use printf:
Code:
#!/bin/bash
printf "%-32s %s\n" "File Name :" "$0"
printf "%-32s %s\n" "First Argument :" "$1"
printf "%-32s %s\n" "Second Argument :" "$2"
printf "%-32s %s\n" "Quoted Values :" "$*"
printf "%-32s %s\n" "Total Number of Arguments :" "$#"
printf "%-32s %s\n" "PID of the scipt :" "$$"
printf "%-32s %s\n" "PID of last background process :" "$!"
 
Old 04-17-2016, 11:28 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,377

Rep: Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040Reputation: 3040
or "man tabs"
 
Old 04-18-2016, 12:02 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,760

Rep: Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050
If you wanted to do it by hand I would do:
Code:
#!/usr/bin/env bash

cat <<-EOF
  File Name			  : $0
  First Argument		  : $1
  Second Argument		  : $2
  Quoted Values			  : $*
  Total Number of Arguments	  : $#
  PID of the script		  : $$
  PID of last background process  : $!
EOF
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to set tab space abhinav4 Linux - Newbie 5 08-22-2012 11:17 AM
[SOLVED] date space in between not tab ted_chou12 Linux - Newbie 2 03-29-2011 08:05 PM
[SOLVED] how to distinguish between tab and space in a file akhand jyoti Linux - Newbie 3 03-22-2011 03:12 AM
Cygwin and space issue in a script. angel115 Programming 4 05-22-2008 08:43 AM
Tab space in VI (M) ar1 Linux - Software 1 12-08-2003 12:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration