Sponsored Content
Top Forums Shell Programming and Scripting Shell Script Comment code blocks in a bash source file Post 302986916 by HiFuture0801 on Thursday 1st of December 2016 02:32:52 PM
Old 12-01-2016
Bug Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you.
I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I know that there is a build in command : would help. But I still have no idea how should I start this.
Should I read the source file first, Then output it as another file?

Here is an example:

Original Source File:
Code:
Final=$(date -d "2016-12-15 14:00" "+%j")
while true ; do
  Today=$(date "+%j")
  Days=$((Final - Today))
  if (( Days >= 14 )) ; then
    echo party
  elif (( Days >= 2 )) ; then
    echo study
  elif (( Days == 1 )) ; then
    for Count in 1 2 3   # loop 2
      do
      echo panic
    done   # loop 2
  else
    break
  fi
  sleep 8h
done

After Script:
Code:
Final=$(date -d "2016-12-15 14:00" "+%j")
while true ; do   # loop 1
  Today=$(date "+%j")
  Days=$((Final - Today))
  if (( Days >= 14 )) ; then   # selection 1
    echo party
  elif (( Days >= 2 )) ; then
    echo study
  elif (( Days == 1 )) ; then
    for Count in 1 2 3   # loop 2
      do
      echo panic
    done   # loop 2
  else
    break
  fi   # selection 1
  sleep 8h
done   # loop 1

Here is some other requirement:
Read from standard input, write to standard output.
At the end of any line containing while until for add the comment: # loop n
At the end of any line containing done add the comment: # loop n
At the end of any line containing if case add the comment: # selection n
At the end of any line containing fi esac add the comment: # selection n

Last edited by HiFuture0801; 12-01-2016 at 03:49 PM.. Reason: Provide Example
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Source Code

Can somebody give me the link to get the source code of BASH? (1 Reply)
Discussion started by: bhargava
1 Replies

2. Shell Programming and Scripting

Protect shell script source code

Hello, Is there any way where a shell scripts source code can be protected? Basically, I'm after to convert shell scripts into to some form of binaries so that my shell script source code can be protected. Forgot to mention, this is on solaris. Many thx, kam (6 Replies)
Discussion started by: jkkstar
6 Replies

3. Shell Programming and Scripting

Tidy shell script source file

Hi all, Is there a tool to tidy up shell script source file and reformat it. Preferably I am looking for a perfect tool to do this. Also I have heard it is possible to do with emacs editor but unfortunately it is looking very different and new from vi. Emacs is new to me and I could not find... (1 Reply)
Discussion started by: meharo
1 Replies

4. Shell Programming and Scripting

Source Env file in the Shell Script

Hi I am having a script which sets the application environment. In this script i am sourcing the applications env file, when i am debugging the script i see its executing all the environment values and all the variable values are set properply. Once this main shell script executes, then... (4 Replies)
Discussion started by: umakanthly
4 Replies

5. Shell Programming and Scripting

Shell Script to display function names (called & defined) in a C++ Source Code

Hello to all, I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Discussion started by: frozensmilz
2 Replies

6. Shell Programming and Scripting

best way for removing comment from shell scripts -- bash

Again a comment removal requirement from me, refer my previous problem & solution for removing comment from ruby scripts: https://www.unix.com/shell-programming-scripting/118296-best-way-removing-comment-ruby-program.html This time, it is for stripping of comments from Shell Script. I search for... (2 Replies)
Discussion started by: thegeek
2 Replies

7. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

8. Shell Programming and Scripting

HOW to run a bash-code in a c-shell script ??

Is there a way to run some code in a C-shell script by different shell, like bash? I have that situation. I have prepared and perfectly workable bash-skript that now I have to execute under C-shell script, divide it on steps and without creating a new files (with the bash-code parts.) For... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

Need to comment some code via script

Hi, I am writing a shell script, which should comment a if-fi loop in a file. From google i found that, we can use below qualifier to comment a section of code, :<<COMMENT COMMENT But i could not place these keywords before and after if-fi loop. Any help would be appreciated. Finally the... (2 Replies)
Discussion started by: successlin
2 Replies

10. Shell Programming and Scripting

Dividing tab blocks in bash script

Hi everyone, I have a data.xml file which only contains thousands of data (tag) blocks. A part of the file looks exactly like this; <data> Line Line Line </data> <data> Line Line Line </data> the rest of the file is simply a repetition of this part. Here each data block contains a... (8 Replies)
Discussion started by: hayreter
8 Replies
CPANPLUS::Shell(3pm)					 Perl Programmers Reference Guide				      CPANPLUS::Shell(3pm)

NAME
CPANPLUS::Shell - base class for CPANPLUS shells SYNOPSIS
use CPANPLUS::Shell; # load the shell indicated by your # config -- defaults to # CPANPLUS::Shell::Default use CPANPLUS::Shell qw[Classic] # load CPANPLUS::Shell::Classic; my $ui = CPANPLUS::Shell->new(); my $name = $ui->which; # Find out what shell you loaded $ui->shell; # run the ui shell DESCRIPTION
This module is the generic loading (and base class) for all "CPANPLUS" shells. Through this module you can load any installed "CPANPLUS" shell. Just about all the functionality is provided by the shell that you have loaded, and not by this class (which merely functions as a generic loading class), so please consult the documentation of your shell of choice. BUG REPORTS
Please report bugs or other issues to <bug-cpanplus@rt.cpan.org<gt>. AUTHOR
This module by Jos Boumans <kane@cpan.org>. COPYRIGHT
The CPAN++ interface (of which this module is a part of) is copyright (c) 2001 - 2007, Jos Boumans <kane@cpan.org>. All rights reserved. This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. SEE ALSO
CPANPLUS::Shell::Default, CPANPLUS::Shell::Classic, cpanp perl v5.18.2 2014-01-06 CPANPLUS::Shell(3pm)
All times are GMT -4. The time now is 03:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy