Results 1 to 1 of 1
I finished my bash script I was having issues with the other day, and figured I'd let anybody who wanted have a look at it (or have it for that ...
- 05-18-2011 #1Just Joined!
- Join Date
- Nov 2010
- Location
- Alaska
- Posts
- 55
Programmer's Touch (Done)
I finished my bash script I was having issues with the other day, and figured I'd let anybody who wanted have a look at it (or have it for that matter). Thanks for the help again.
Also, Line 155 has a sudo chmod 755 command because this version of knoppix doesn't save my files with the right permissions (for some bizarre reason), so feel free to remove it.
Probably not to great, but I want want to contribute something to the Linux community. Hope somebody likes this or at least finds it useful.Code:#!/bin/bash function blankline { echo "" >> $file } function pblankline { echo "" } function makefunc { until [ "$add" = "no" -o "$add" = "n" ]; do pblankline echo "What type of function do you want to add?" read type pblankline echo "What do you want to name your function?" read funcname pblankline until [[ $arg =~ ^[0-9]+$ ]]; do echo "How many arguments?" read arg pblankline if ! [[ $arg =~ ^[0-9]+$ ]]; then echo "Please enter a positive number" pblankline fi done if [ $arg != 0 ]; then for ((x=1;x<=$arg;x=x+1));do if [ "$x" = 1 ]; then echo "What is your argument? Enter in the form of \"type arg\"." else echo "What is your argument?" fi read input pblankline if [ $x != $arg ]; then argarray[$x]=$input, else argarray[$x]=$input fi done addb=0 argar="" for((n=1;n<=$arg;n=n+1));do argar=$argar${argarray[$n]} done fi echo "$type function $funcname("$argar") {" >> $file blankline echo "}" >> $file blankline echo "Would you like to add another function? You must type n or no to end the loop." read add arg="" done } pwd=p addb=1 yes="no" until [ "$save" = "yes" -o "$save" = "y" ];do echo "Type the name of your file. Do not include the file extention." read filename pblankline echo "Type the file extention. Do not include a dot." read ext pblankline file=$filename"."$ext save="y" if [ -f "$file" ]; then echo "This file already exists, would you like to overwrite?" read save pblankline if [ "$save" = "yes" -o "$save" = "y" ]; then rm $file else echo "Then please try again." pblankline fi fi done case $ext in bash) echo "#!/bin/bash" > $file;blankline;; java) touch $file echo "Would you like to add anything to the file? (functions, imports, etc.)" read add if [ "$add" = "yes" -o "$add" = "y" ]; then let addb=0 pblankline echo "Would you like to import any java files?" read add pblankline if [ "$add" = "yes" -o "$add" = "y" ]; then echo "Type stop to end. Enter in the form of \"java.blah.blah\"." until [ "$add" = "stop" ]; do echo "What class would you like to import?" read add pblankline if [ "$add" != "stop" ]; then echo "import "$add";" >> $file fi done blankline fi fi echo "public class $name {" >> $file echo " public static void main(String[] args) {" >> $file blankline if [ "$addb" = 0 ]; then echo "Would you like to declare any functions?" read add if [ "$add" = "yes" -o "$add" = "y" ]; then makefunc fi fi echo " " >> $file;; cpp) touch $file echo "Would you like to add anything to the file? (functions, includes, etc.)" read add pblankline if [ "$add" = "yes" -o "$add" = "y" ]; then addb=0 echo "Would you like to include any files? (iostream is already added)" read add pblankline if [ "$add" = "yes" -o "$add" = "y" ]; then echo "Type stop to end. Enter in the form of \"blah\"." until [ "$add" = "stop" ]; do echo "What file would you like to include?" read add pblankline if [ "$add" != "stop" ]; then echo "#include <"$add">" >> $file fi done fi fi echo "#include <iostream>" >> $file echo "using namespace std;" >> $file blankline if [ "$addb" = 0 ]; then echo "Would you like to declare any functions?" read add if [ "$add" = "yes" -o "$add" = "y" ]; then makefunc fi fi echo "int main () {" >> $file echo " " >> $file;; s) echo "main:" > $file;blankline;; *) touch $file esac sudo chmod 755 $p$file
From,
Dood


Reply With Quote