Formatter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatter
# 1  
Old 01-03-2017
Formatter

Hi,

I have been searching for a tool or online URL to format (beautify) UNIX shell script without any luck.

Could you please assist any online link or tool to format UNIX shell script.
I've couple of legacy scripts needs to be formatted.

Thank you in advance.

Regards,
Pointers
# 2  
Old 01-03-2017
Hi.

I use the item below fairly often. You'll need Python to run it. See the home page for details ... cheers, drl
Code:
beautysh        Tidy bash scripts, written in python3. (what)
Path    : ~/bin/beautysh
Version : - ( local: RepRev 1.4, ~/bin/beautysh, 2016-03-31 )
Length  : 174 lines
Type    : Python script, ASCII text executable
Shebang : #!/usr/bin/env python3
Home    : https://github.com/bemeurer/beautysh
Modules : (for python codes)
  re
  sys

This User Gave Thanks to drl For This Post:
# 3  
Old 01-04-2017
Beautify code

Hi,

Thank you for your response.

I don't know about python.

Can you please help me how to proceed further.
I've downloaded the file beautysh.py under the -
---/bemeurer/beautysh/tree/master/beautysh

just saved the file in beautify.py and chmod 777 beautify.py then ran like
Code:
python beautify.py

I am getting error.

Am I using correct file and running properly.

Thank you in advance.

Regards,
Pointers

Last edited by Don Cragun; 01-04-2017 at 03:45 AM.. Reason: Add CODE and ICODE tags again.
# 4  
Old 01-04-2017
It is nice to know the you are getting an error... But if you don't tell us what error you are getting, it is hard for us to guess at what might be wrong.

Please show us the exact diagnostic messages you are getting (in CODE tags) when you try to run your command.
# 5  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. 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

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

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
Login or Register to Ask a Question