Sponsored Content
Full Discussion: Formatter
Top Forums Shell Programming and Scripting Formatter Post 302988883 by drl on Wednesday 4th of January 2017 11:02:09 AM
Old 01-04-2017
Hi, pointers1234.

Note well Don's advice. Your lack of a specific error message causes us to perform another turn-around, asking you about the error message, and you responding before we can get down to business. A time waste on both our parts.

I usually use beautysh interactively, but here is the use in a script, used the same way. I usually post scripts, so that you can see the context, input and output. Note that the operative line is:
Code:
beautysh $FILE

and, because beautysh is in my PATH (namely in ~/bin), it is executed just like a system command.
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate beautysh.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
em() { pe "$*" >&2 ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C beautysh

FILE=${1-s1.sh}
cp sacred.sh $FILE

pl " Input data file $FILE:"
cat $FILE

pl " Results:"
beautysh $FILE
cat $FILE

exit 0

producing:
Code:
$ ./s1 

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie) 
bash GNU bash 4.3.30
beautysh - ( local: RepRev 1.4, ~/bin/beautysh, 2016-03-31 )

-----
 Input data file s1.sh:
#!/usr/bin/env bash

# @(#) s1.sh    Demonstrate tidy scripts, beautysh.

# Functions.

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

echo " Hello, world."
if [ $# -gt 0 ]
then
echo " Argument 1 is $1"
fi

        if [ $# -ge 2 ] ; then
                echo " Argument 2 is $2"
                if [[ $2 =~ b ]]
                then
                  echo " Hit!, arg 2 was a b."
                  fi
                        fi

case $0 in
run)    ./run ;;

        xxx)    ./exit
        ;;

        *)      echo " Error -- unknown keyword: $0." >&2 ; exit 1 ;;

             esac

exit 0

-----
 Results:
#!/usr/bin/env bash

# @(#) s1.sh    Demonstrate tidy scripts, beautysh.

# Functions.

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

echo " Hello, world."
if [ $# -gt 0 ]
then
  echo " Argument 1 is $1"
fi

if [ $# -ge 2 ] ; then
  echo " Argument 2 is $2"
  if [[ $2 =~ b ]]
  then
    echo " Hit!, arg 2 was a b."
  fi
fi

case $0 in
  run)  ./run ;;
  
  xxx)  ./exit
  ;;
  
  *)    echo " Error -- unknown keyword: $0." >&2 ; exit 1 ;;
  
esac

exit 0

Best wishes ... cheers, drl
 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix Formatter

HI all, Is their any UNIX shell script code formatter that work on windows ? If so where can I get it ? I want to format the shell scripts in with proper indentation etc... Thanks...In Advance (0 Replies)
Discussion started by: dhananjaysk
0 Replies

2. Shell Programming and Scripting

code formatter for shell script

hello, do anybody know a program to format a shell script code ? i tried "editrocket.com" but this product doesn't format a shell script code. i searched for programs but can't find a shell script code formatter. i have to change a shell script and the style of code is ..... regards (5 Replies)
Discussion started by: bora99
5 Replies

3. Shell Programming and Scripting

File/string formatter script?

Hi all, I have a config file that contains some text as below: server01 :/u01/app/oracle/admin/db01/adump :*.dmp,5 :compress :/bin/gzip server01 :/u01/app/oracle/admin/db04/adump :*.aud,5 :remove :/bin/rm server01 ... (4 Replies)
Discussion started by: newbie_01
4 Replies
ECHO(1) 						    BSD General Commands Manual 						   ECHO(1)

NAME
echo -- write arguments to the standard output SYNOPSIS
echo [-n] [string ...] DESCRIPTION
The echo utility writes any specified operands, separated by single blank (' ') characters and followed by a newline (' ') character, to the standard output. The following option is available: -n Do not print the trailing newline character. This may also be achieved by appending 'c' to the end of the string, as is done by iBCS2 compatible systems. Note that this option as well as the effect of 'c' are implementation-defined in IEEE Std 1003.1-2001 (``POSIX.1'') as amended by Cor. 1-2002. Applications aiming for maximum portability are strongly encouraged to use printf(1) to sup- press the newline character. Some shells may provide a builtin echo command which is similar or identical to this utility. Most notably, the builtin echo in sh(1) does not accept the -n option. Consult the builtin(1) manual page. EXIT STATUS
The echo utility exits 0 on success, and >0 if an error occurs. SEE ALSO
builtin(1), csh(1), printf(1), sh(1) STANDARDS
The echo utility conforms to IEEE Std 1003.1-2001 (``POSIX.1'') as amended by Cor. 1-2002. BSD
April 12, 2003 BSD
All times are GMT -4. The time now is 10:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy