Making a bash c# compiler? [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • Replace one substring for another string in shell script

    6 answers




I want to start developing in c#, however I use Linux and VSCode for development and VSCode doesn't run the code due to some error that I can't find an answer to, so I decided with the help of this link (Run C# code on linux terminal) to make a bash script that does this part of the code:



mcs -out:hello.exe hello.cs
mono hello.exe


I made it like this so far:



#Trial
function cs_compiler(){
mcs -out:$2 $1
mono $2
}


It does work however I want to make it so that $2 (the second parameter) is automatically named after the $1(the first parameter), thus I needn't write $2's value and just write $1 create an exe with the same name and run that exe with mono. The second thing I want is to check if the exe form of the cs file already exists, if so just run it (mono) without doing mcs-out.



I'm sorry if this is of inconvenience, I'm new to stackoverflow and coding.










share|improve this question













marked as duplicate by dlatikay, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • why not function ... mcs -out:$1.exe $1.cs ; mono $1.exe... ? Also for I want is to check if the exe form...exists, if [ ! -f $1.exe ] ; then msc .... else $1.exe ; fi . If you get syntax errors on your new code, use shellheck.net to point you in the right direction to fix them. The error messages are a little obscure for a new user, but think about where in the code the error is flagged and the error message provided and take your best guess to try and fix it. Good luck....
    – shellter
    Nov 11 at 15:22












  • And I agree with @dlatikay, testing for an existing file and running it will likely mean you keep running old, broken code. The make program is designed for these situations, but you'll need more help than we can provide on StackOverflow to get up to speed (probably). See if you can find someone local that can help you with your "Hello World" make file. Good luck.
    – shellter
    Nov 11 at 15:28

















up vote
-1
down vote

favorite













This question already has an answer here:




  • Replace one substring for another string in shell script

    6 answers




I want to start developing in c#, however I use Linux and VSCode for development and VSCode doesn't run the code due to some error that I can't find an answer to, so I decided with the help of this link (Run C# code on linux terminal) to make a bash script that does this part of the code:



mcs -out:hello.exe hello.cs
mono hello.exe


I made it like this so far:



#Trial
function cs_compiler(){
mcs -out:$2 $1
mono $2
}


It does work however I want to make it so that $2 (the second parameter) is automatically named after the $1(the first parameter), thus I needn't write $2's value and just write $1 create an exe with the same name and run that exe with mono. The second thing I want is to check if the exe form of the cs file already exists, if so just run it (mono) without doing mcs-out.



I'm sorry if this is of inconvenience, I'm new to stackoverflow and coding.










share|improve this question













marked as duplicate by dlatikay, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • why not function ... mcs -out:$1.exe $1.cs ; mono $1.exe... ? Also for I want is to check if the exe form...exists, if [ ! -f $1.exe ] ; then msc .... else $1.exe ; fi . If you get syntax errors on your new code, use shellheck.net to point you in the right direction to fix them. The error messages are a little obscure for a new user, but think about where in the code the error is flagged and the error message provided and take your best guess to try and fix it. Good luck....
    – shellter
    Nov 11 at 15:22












  • And I agree with @dlatikay, testing for an existing file and running it will likely mean you keep running old, broken code. The make program is designed for these situations, but you'll need more help than we can provide on StackOverflow to get up to speed (probably). See if you can find someone local that can help you with your "Hello World" make file. Good luck.
    – shellter
    Nov 11 at 15:28















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • Replace one substring for another string in shell script

    6 answers




I want to start developing in c#, however I use Linux and VSCode for development and VSCode doesn't run the code due to some error that I can't find an answer to, so I decided with the help of this link (Run C# code on linux terminal) to make a bash script that does this part of the code:



mcs -out:hello.exe hello.cs
mono hello.exe


I made it like this so far:



#Trial
function cs_compiler(){
mcs -out:$2 $1
mono $2
}


It does work however I want to make it so that $2 (the second parameter) is automatically named after the $1(the first parameter), thus I needn't write $2's value and just write $1 create an exe with the same name and run that exe with mono. The second thing I want is to check if the exe form of the cs file already exists, if so just run it (mono) without doing mcs-out.



I'm sorry if this is of inconvenience, I'm new to stackoverflow and coding.










share|improve this question














This question already has an answer here:




  • Replace one substring for another string in shell script

    6 answers




I want to start developing in c#, however I use Linux and VSCode for development and VSCode doesn't run the code due to some error that I can't find an answer to, so I decided with the help of this link (Run C# code on linux terminal) to make a bash script that does this part of the code:



mcs -out:hello.exe hello.cs
mono hello.exe


I made it like this so far:



#Trial
function cs_compiler(){
mcs -out:$2 $1
mono $2
}


It does work however I want to make it so that $2 (the second parameter) is automatically named after the $1(the first parameter), thus I needn't write $2's value and just write $1 create an exe with the same name and run that exe with mono. The second thing I want is to check if the exe form of the cs file already exists, if so just run it (mono) without doing mcs-out.



I'm sorry if this is of inconvenience, I'm new to stackoverflow and coding.





This question already has an answer here:




  • Replace one substring for another string in shell script

    6 answers








bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 8:47









Apoqlite

1




1




marked as duplicate by dlatikay, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by dlatikay, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • why not function ... mcs -out:$1.exe $1.cs ; mono $1.exe... ? Also for I want is to check if the exe form...exists, if [ ! -f $1.exe ] ; then msc .... else $1.exe ; fi . If you get syntax errors on your new code, use shellheck.net to point you in the right direction to fix them. The error messages are a little obscure for a new user, but think about where in the code the error is flagged and the error message provided and take your best guess to try and fix it. Good luck....
    – shellter
    Nov 11 at 15:22












  • And I agree with @dlatikay, testing for an existing file and running it will likely mean you keep running old, broken code. The make program is designed for these situations, but you'll need more help than we can provide on StackOverflow to get up to speed (probably). See if you can find someone local that can help you with your "Hello World" make file. Good luck.
    – shellter
    Nov 11 at 15:28




















  • why not function ... mcs -out:$1.exe $1.cs ; mono $1.exe... ? Also for I want is to check if the exe form...exists, if [ ! -f $1.exe ] ; then msc .... else $1.exe ; fi . If you get syntax errors on your new code, use shellheck.net to point you in the right direction to fix them. The error messages are a little obscure for a new user, but think about where in the code the error is flagged and the error message provided and take your best guess to try and fix it. Good luck....
    – shellter
    Nov 11 at 15:22












  • And I agree with @dlatikay, testing for an existing file and running it will likely mean you keep running old, broken code. The make program is designed for these situations, but you'll need more help than we can provide on StackOverflow to get up to speed (probably). See if you can find someone local that can help you with your "Hello World" make file. Good luck.
    – shellter
    Nov 11 at 15:28


















why not function ... mcs -out:$1.exe $1.cs ; mono $1.exe... ? Also for I want is to check if the exe form...exists, if [ ! -f $1.exe ] ; then msc .... else $1.exe ; fi . If you get syntax errors on your new code, use shellheck.net to point you in the right direction to fix them. The error messages are a little obscure for a new user, but think about where in the code the error is flagged and the error message provided and take your best guess to try and fix it. Good luck....
– shellter
Nov 11 at 15:22






why not function ... mcs -out:$1.exe $1.cs ; mono $1.exe... ? Also for I want is to check if the exe form...exists, if [ ! -f $1.exe ] ; then msc .... else $1.exe ; fi . If you get syntax errors on your new code, use shellheck.net to point you in the right direction to fix them. The error messages are a little obscure for a new user, but think about where in the code the error is flagged and the error message provided and take your best guess to try and fix it. Good luck....
– shellter
Nov 11 at 15:22














And I agree with @dlatikay, testing for an existing file and running it will likely mean you keep running old, broken code. The make program is designed for these situations, but you'll need more help than we can provide on StackOverflow to get up to speed (probably). See if you can find someone local that can help you with your "Hello World" make file. Good luck.
– shellter
Nov 11 at 15:28






And I agree with @dlatikay, testing for an existing file and running it will likely mean you keep running old, broken code. The make program is designed for these situations, but you'll need more help than we can provide on StackOverflow to get up to speed (probably). See if you can find someone local that can help you with your "Hello World" make file. Good luck.
– shellter
Nov 11 at 15:28














1 Answer
1






active

oldest

votes

















up vote
0
down vote













From man basename:



Strip directory and suffix from filenames


Sadly you have to know suffix in advance to use it. So:



cs_compiler() {
local infile outfile
infile="$1"
outfile="$(dirname "$1")/$(basename "$1" .cs)"
mcs -out:"$outfile" "$infile"
mono "$oufile"
}



  1. Quote your variables.

  2. Indent your code


But maybe better would be to remove the part after dot:



infilename=$(basename -- "$1") # some temp variable
outfile="$(dirname "$infile")/${infilename##*.}"


See this post on how to extract filename from files.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    From man basename:



    Strip directory and suffix from filenames


    Sadly you have to know suffix in advance to use it. So:



    cs_compiler() {
    local infile outfile
    infile="$1"
    outfile="$(dirname "$1")/$(basename "$1" .cs)"
    mcs -out:"$outfile" "$infile"
    mono "$oufile"
    }



    1. Quote your variables.

    2. Indent your code


    But maybe better would be to remove the part after dot:



    infilename=$(basename -- "$1") # some temp variable
    outfile="$(dirname "$infile")/${infilename##*.}"


    See this post on how to extract filename from files.






    share|improve this answer

























      up vote
      0
      down vote













      From man basename:



      Strip directory and suffix from filenames


      Sadly you have to know suffix in advance to use it. So:



      cs_compiler() {
      local infile outfile
      infile="$1"
      outfile="$(dirname "$1")/$(basename "$1" .cs)"
      mcs -out:"$outfile" "$infile"
      mono "$oufile"
      }



      1. Quote your variables.

      2. Indent your code


      But maybe better would be to remove the part after dot:



      infilename=$(basename -- "$1") # some temp variable
      outfile="$(dirname "$infile")/${infilename##*.}"


      See this post on how to extract filename from files.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        From man basename:



        Strip directory and suffix from filenames


        Sadly you have to know suffix in advance to use it. So:



        cs_compiler() {
        local infile outfile
        infile="$1"
        outfile="$(dirname "$1")/$(basename "$1" .cs)"
        mcs -out:"$outfile" "$infile"
        mono "$oufile"
        }



        1. Quote your variables.

        2. Indent your code


        But maybe better would be to remove the part after dot:



        infilename=$(basename -- "$1") # some temp variable
        outfile="$(dirname "$infile")/${infilename##*.}"


        See this post on how to extract filename from files.






        share|improve this answer












        From man basename:



        Strip directory and suffix from filenames


        Sadly you have to know suffix in advance to use it. So:



        cs_compiler() {
        local infile outfile
        infile="$1"
        outfile="$(dirname "$1")/$(basename "$1" .cs)"
        mcs -out:"$outfile" "$infile"
        mono "$oufile"
        }



        1. Quote your variables.

        2. Indent your code


        But maybe better would be to remove the part after dot:



        infilename=$(basename -- "$1") # some temp variable
        outfile="$(dirname "$infile")/${infilename##*.}"


        See this post on how to extract filename from files.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 8:55









        Kamil Cuk

        7,6471222




        7,6471222















            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python