Guest User

Untitled

a guest
Nov 30th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. #!/bin/bash
  2. # geany kääntää ja suorittaa ohjelman F5-painikkeella. geany lähettää tänne argumenttina 1 hakemiston ja argumenttina 2 tiedostonimen
  3. #
  4. # geanyn build_commands --> execute --> geany_f5 %d %f  (ja tän joutuu tekemään eri tiedostopäätteille siellä erikseen, eli kun käsittelee ekaa kertaa. py tiedostoa .cpp tiedostoa jne
  5.  
  6. hakemisto=$1
  7. tiedosto=$(basename -- "$2")
  8. paate="${tiedosto##*.}"
  9. basetiedosto="${tiedosto%.*}"
  10.  
  11. ekarivi=$(cat $tiedosto|head -n 1)
  12. if [[ "$ekarivi" == "#!"* ]]; then  #ekalla rivillä esim #!/usr/bin/env python3
  13.     suorittaja=$(echo $ekarivi|cut -c 3-)
  14.     $suorittaja "$hakemisto/$tiedosto"
  15.  
  16. elif [[ "$paate" == "cpp" ]];then #------------------------------------------- cpp
  17.     cd $hakemisto
  18.     g++ ./"$tiedosto" -o ./"$basetiedosto" -std=gnu++17 && ./"$basetiedosto"
  19.  
  20.  
  21. elif [[ "$paate" == "py" ]];then #------------------------------------------ py
  22.     cd $hakemisto
  23.     /usr/bin/env python3 $tiedosto
  24.  
  25. else
  26.     echo "Ei osattu suorittaa. Varmista että tiedostolla on tunnettu tiedostopääte tai ekalla rivillä on #!/....."
  27. fi
Advertisement
Add Comment
Please, Sign In to add comment