0

I have written the below bash script to compile and run my C programs, and added it to the 'Manage External Tools' list.

#! /bin/bash
cd /home/prm/Documents/Anubhav/C
FILE="$(ls -Art | tail -n 1)" # to get the latest updated file
gcc $FILE # compilation
./a.out # execution

With this I am able to compile and run my last saved C programs. But I am unable to send any value to the program since the output displays on 'Output Tools' of Gedit rather than on Terminal. I also tried various input options from the drop-down menu but none of them worked for me.

Screenshot of Editor with ouput

Kulfy
  • 17,416
  • 26
  • 64
  • 103
  • Related: [Why doesn't “cd” work in a shell script?](https://askubuntu.com/questions/481715/why-doesnt-cd-work-in-a-shell-script) – Kulfy Jun 22 '20 at 18:28
  • @Kulfy Can you explain? The effect of `cd` persists to the end of the shell in which it is run (or the next directory change done from that shell), so it covers the commands in that script that need it. If the goal were to change the working directory of some other already-existing process, such as Gedit, then that would fail, but that doesn't seem to be the problem here. If that *is* the problem here, I think it bears explanation in an answer, and that this would still not be a duplicate of [that general question](https://askubuntu.com/questions/481715/why-doesnt-cd-work-in-a-shell-script). – Eliah Kagan Jun 22 '20 at 23:06

0 Answers0