Tool to auto-format shell script












2















I got some code above which was into a pdf document, wherever I try to post it indentation is terrible, I would like to get it to a proper formatting for debbuging. Here is my code:



    #!/bin/bash 
# to measure average power consumed in 30sec with 1sec sampling interval
duration
=
30
interval
=
1
RAILS
=(
"
VDD_IN /sys/bus/i2c/drivers/ina3221x/0-
0041/iio:device1/in_power0_input"
"VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-
0040/iio:device0/in_power0_input"
"VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-
0041/iio:device1/in_power1_input"
"VDD_SYS_SOC /sys/bus/i2c/drivers/ina3221x/0-
0040/iio:device0/in_power1_input"
"VDD_SYS_DDR /sys/bus/i2c/drivers/ina3221x/0-
0041/iio:device1/in_power2_input"
"VDD_4V0_WIFI /sys/bus/i2c/drivers/ina3221x/0-
0040/iio:device0/in_power2_input"
)
for
((
i
=
0
;
i
<
${#RAILS[@]}
;
i++
));
do
Optimizin
g Jetson TX2 for Power and Performance
Jetson TX2
TDG
-08413-
001_v1.0
| 28
read
name
[
$i]
node
[
$i]
pwr_sum
[
$i]
pwr_count
[
$i]
<<<$(echo
"${RAILS[$i]} 0 0")
done
end_time
=$(($(date '+%s')
+
duration
))
while
[
$(date '+%s')
-
le
$end_time
];
do
for
((
i
=
0
;
i
<
${#RAILS[@]}
;
i++
));
do
pwr_sum
[
$i]=$((
${pwr_sum[$i]}
+
$(cat ${node[$i]})))
&&
pwr_count
[
$i]=$((
${pwr_count[$i]}
+
1
))
done
sleep
$interval
done
echo
"RAIL,POWER_AVG"
for
((
i
=
0
;
i
<
${#RAILS[@]}
;
i++
));
do
pwr_avg
=$((
${pwr_sum[$i]}
/
${pwr_count[$i]}
))
echo
"${name[$i]},$pwr_avg"
done


I'm doign it manually but I wonder if it could be done automatically.










share|improve this question














bumped to the homepage by Community 2 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    2















    I got some code above which was into a pdf document, wherever I try to post it indentation is terrible, I would like to get it to a proper formatting for debbuging. Here is my code:



        #!/bin/bash 
    # to measure average power consumed in 30sec with 1sec sampling interval
    duration
    =
    30
    interval
    =
    1
    RAILS
    =(
    "
    VDD_IN /sys/bus/i2c/drivers/ina3221x/0-
    0041/iio:device1/in_power0_input"
    "VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-
    0040/iio:device0/in_power0_input"
    "VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-
    0041/iio:device1/in_power1_input"
    "VDD_SYS_SOC /sys/bus/i2c/drivers/ina3221x/0-
    0040/iio:device0/in_power1_input"
    "VDD_SYS_DDR /sys/bus/i2c/drivers/ina3221x/0-
    0041/iio:device1/in_power2_input"
    "VDD_4V0_WIFI /sys/bus/i2c/drivers/ina3221x/0-
    0040/iio:device0/in_power2_input"
    )
    for
    ((
    i
    =
    0
    ;
    i
    <
    ${#RAILS[@]}
    ;
    i++
    ));
    do
    Optimizin
    g Jetson TX2 for Power and Performance
    Jetson TX2
    TDG
    -08413-
    001_v1.0
    | 28
    read
    name
    [
    $i]
    node
    [
    $i]
    pwr_sum
    [
    $i]
    pwr_count
    [
    $i]
    <<<$(echo
    "${RAILS[$i]} 0 0")
    done
    end_time
    =$(($(date '+%s')
    +
    duration
    ))
    while
    [
    $(date '+%s')
    -
    le
    $end_time
    ];
    do
    for
    ((
    i
    =
    0
    ;
    i
    <
    ${#RAILS[@]}
    ;
    i++
    ));
    do
    pwr_sum
    [
    $i]=$((
    ${pwr_sum[$i]}
    +
    $(cat ${node[$i]})))
    &&
    pwr_count
    [
    $i]=$((
    ${pwr_count[$i]}
    +
    1
    ))
    done
    sleep
    $interval
    done
    echo
    "RAIL,POWER_AVG"
    for
    ((
    i
    =
    0
    ;
    i
    <
    ${#RAILS[@]}
    ;
    i++
    ));
    do
    pwr_avg
    =$((
    ${pwr_sum[$i]}
    /
    ${pwr_count[$i]}
    ))
    echo
    "${name[$i]},$pwr_avg"
    done


    I'm doign it manually but I wonder if it could be done automatically.










    share|improve this question














    bumped to the homepage by Community 2 hours ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      2












      2








      2








      I got some code above which was into a pdf document, wherever I try to post it indentation is terrible, I would like to get it to a proper formatting for debbuging. Here is my code:



          #!/bin/bash 
      # to measure average power consumed in 30sec with 1sec sampling interval
      duration
      =
      30
      interval
      =
      1
      RAILS
      =(
      "
      VDD_IN /sys/bus/i2c/drivers/ina3221x/0-
      0041/iio:device1/in_power0_input"
      "VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-
      0040/iio:device0/in_power0_input"
      "VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-
      0041/iio:device1/in_power1_input"
      "VDD_SYS_SOC /sys/bus/i2c/drivers/ina3221x/0-
      0040/iio:device0/in_power1_input"
      "VDD_SYS_DDR /sys/bus/i2c/drivers/ina3221x/0-
      0041/iio:device1/in_power2_input"
      "VDD_4V0_WIFI /sys/bus/i2c/drivers/ina3221x/0-
      0040/iio:device0/in_power2_input"
      )
      for
      ((
      i
      =
      0
      ;
      i
      <
      ${#RAILS[@]}
      ;
      i++
      ));
      do
      Optimizin
      g Jetson TX2 for Power and Performance
      Jetson TX2
      TDG
      -08413-
      001_v1.0
      | 28
      read
      name
      [
      $i]
      node
      [
      $i]
      pwr_sum
      [
      $i]
      pwr_count
      [
      $i]
      <<<$(echo
      "${RAILS[$i]} 0 0")
      done
      end_time
      =$(($(date '+%s')
      +
      duration
      ))
      while
      [
      $(date '+%s')
      -
      le
      $end_time
      ];
      do
      for
      ((
      i
      =
      0
      ;
      i
      <
      ${#RAILS[@]}
      ;
      i++
      ));
      do
      pwr_sum
      [
      $i]=$((
      ${pwr_sum[$i]}
      +
      $(cat ${node[$i]})))
      &&
      pwr_count
      [
      $i]=$((
      ${pwr_count[$i]}
      +
      1
      ))
      done
      sleep
      $interval
      done
      echo
      "RAIL,POWER_AVG"
      for
      ((
      i
      =
      0
      ;
      i
      <
      ${#RAILS[@]}
      ;
      i++
      ));
      do
      pwr_avg
      =$((
      ${pwr_sum[$i]}
      /
      ${pwr_count[$i]}
      ))
      echo
      "${name[$i]},$pwr_avg"
      done


      I'm doign it manually but I wonder if it could be done automatically.










      share|improve this question














      I got some code above which was into a pdf document, wherever I try to post it indentation is terrible, I would like to get it to a proper formatting for debbuging. Here is my code:



          #!/bin/bash 
      # to measure average power consumed in 30sec with 1sec sampling interval
      duration
      =
      30
      interval
      =
      1
      RAILS
      =(
      "
      VDD_IN /sys/bus/i2c/drivers/ina3221x/0-
      0041/iio:device1/in_power0_input"
      "VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-
      0040/iio:device0/in_power0_input"
      "VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-
      0041/iio:device1/in_power1_input"
      "VDD_SYS_SOC /sys/bus/i2c/drivers/ina3221x/0-
      0040/iio:device0/in_power1_input"
      "VDD_SYS_DDR /sys/bus/i2c/drivers/ina3221x/0-
      0041/iio:device1/in_power2_input"
      "VDD_4V0_WIFI /sys/bus/i2c/drivers/ina3221x/0-
      0040/iio:device0/in_power2_input"
      )
      for
      ((
      i
      =
      0
      ;
      i
      <
      ${#RAILS[@]}
      ;
      i++
      ));
      do
      Optimizin
      g Jetson TX2 for Power and Performance
      Jetson TX2
      TDG
      -08413-
      001_v1.0
      | 28
      read
      name
      [
      $i]
      node
      [
      $i]
      pwr_sum
      [
      $i]
      pwr_count
      [
      $i]
      <<<$(echo
      "${RAILS[$i]} 0 0")
      done
      end_time
      =$(($(date '+%s')
      +
      duration
      ))
      while
      [
      $(date '+%s')
      -
      le
      $end_time
      ];
      do
      for
      ((
      i
      =
      0
      ;
      i
      <
      ${#RAILS[@]}
      ;
      i++
      ));
      do
      pwr_sum
      [
      $i]=$((
      ${pwr_sum[$i]}
      +
      $(cat ${node[$i]})))
      &&
      pwr_count
      [
      $i]=$((
      ${pwr_count[$i]}
      +
      1
      ))
      done
      sleep
      $interval
      done
      echo
      "RAIL,POWER_AVG"
      for
      ((
      i
      =
      0
      ;
      i
      <
      ${#RAILS[@]}
      ;
      i++
      ));
      do
      pwr_avg
      =$((
      ${pwr_sum[$i]}
      /
      ${pwr_count[$i]}
      ))
      echo
      "${name[$i]},$pwr_avg"
      done


      I'm doign it manually but I wonder if it could be done automatically.







      text-formatting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 31 '18 at 20:10









      vfbsilvavfbsilva

      2,66211227




      2,66211227





      bumped to the homepage by Community 2 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 2 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          What IDE are you using? In VIM, gg=G works reasonably well. If you're using Atom, then see this: https://atom.io/packages/format-shell .






          share|improve this answer
























          • True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

            – m0dular
            May 31 '18 at 23:27






          • 1





            how do I use gg=G in vim?

            – vfbsilva
            Jun 1 '18 at 0:03






          • 1





            How to use gg=G: stackoverflow.com/a/12582414/487992

            – JohnMudd
            Sep 28 '18 at 19:04











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f447190%2ftool-to-auto-format-shell-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          What IDE are you using? In VIM, gg=G works reasonably well. If you're using Atom, then see this: https://atom.io/packages/format-shell .






          share|improve this answer
























          • True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

            – m0dular
            May 31 '18 at 23:27






          • 1





            how do I use gg=G in vim?

            – vfbsilva
            Jun 1 '18 at 0:03






          • 1





            How to use gg=G: stackoverflow.com/a/12582414/487992

            – JohnMudd
            Sep 28 '18 at 19:04
















          0














          What IDE are you using? In VIM, gg=G works reasonably well. If you're using Atom, then see this: https://atom.io/packages/format-shell .






          share|improve this answer
























          • True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

            – m0dular
            May 31 '18 at 23:27






          • 1





            how do I use gg=G in vim?

            – vfbsilva
            Jun 1 '18 at 0:03






          • 1





            How to use gg=G: stackoverflow.com/a/12582414/487992

            – JohnMudd
            Sep 28 '18 at 19:04














          0












          0








          0







          What IDE are you using? In VIM, gg=G works reasonably well. If you're using Atom, then see this: https://atom.io/packages/format-shell .






          share|improve this answer













          What IDE are you using? In VIM, gg=G works reasonably well. If you're using Atom, then see this: https://atom.io/packages/format-shell .







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 31 '18 at 21:30









          KM.KM.

          1,28911321




          1,28911321













          • True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

            – m0dular
            May 31 '18 at 23:27






          • 1





            how do I use gg=G in vim?

            – vfbsilva
            Jun 1 '18 at 0:03






          • 1





            How to use gg=G: stackoverflow.com/a/12582414/487992

            – JohnMudd
            Sep 28 '18 at 19:04



















          • True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

            – m0dular
            May 31 '18 at 23:27






          • 1





            how do I use gg=G in vim?

            – vfbsilva
            Jun 1 '18 at 0:03






          • 1





            How to use gg=G: stackoverflow.com/a/12582414/487992

            – JohnMudd
            Sep 28 '18 at 19:04

















          True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

          – m0dular
          May 31 '18 at 23:27





          True, but OP has a lot of lines that need to be joined together before =. I think it's worth mentioning you can select a range of lines with visual line mode (shift + V, j and k to move up and down), then join them with J.

          – m0dular
          May 31 '18 at 23:27




          1




          1





          how do I use gg=G in vim?

          – vfbsilva
          Jun 1 '18 at 0:03





          how do I use gg=G in vim?

          – vfbsilva
          Jun 1 '18 at 0:03




          1




          1





          How to use gg=G: stackoverflow.com/a/12582414/487992

          – JohnMudd
          Sep 28 '18 at 19:04





          How to use gg=G: stackoverflow.com/a/12582414/487992

          – JohnMudd
          Sep 28 '18 at 19:04


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f447190%2ftool-to-auto-format-shell-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          宮崎県

          濃尾地震

          6月16日