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: After Script:
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
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.
Please review the rules, which you agreed to when you registered, if you have not already done so.
More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.
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)
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)
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)
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)
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)
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)
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)
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)
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)