-1

Hello my issue is that I can't add the shebang to the first line when the application launches the nano editor. I am manually adding #!/bin/bash to the first line.

The code is here at github https://github.com/plutesci/Iwanttobash/blob/master/Icode_demo.bash

It seems to be this line, 1 ) nano $text.bash ; umask 022 $text.bash ;; This is part of a larger section of code.

selection=
until [ "$selection" = "0" ]; do
echo "
ICODE MENU
1 - Start a new Bash Script 
2 - Make it Executable
3 - Run Bash Program
4 - Continue working on script
5 - start a new Python Idle
6 - Open a new shell
7 - Create Automatic Shell scripts
8 - Add a shebang
9 - Help
0 - exit program
"
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
    1 ) nano $text.bash ; umask 022 $text.bash ;;
    2 ) chmod 755 $text.bash ;;
    3 ) gnome-terminal `./$text.bash` ;; 
    4 ) nano $text.bash ;;
    5 ) idle ;;
    6 ) gnome-terminal ;;
    7 ) nano ;; # would be something like grep a special crafted document
    8 ) cat > $text.bash | `#!/bin/bash` ;;
    9 ) cat "icodehelp" ;;
    0 ) exit ;;
    * ) echo "Please enter 1, 2, 3, 4, 5, 6, 7, 8,9, or 0"
    esac
done

I'm attempting to add #!/bin/bash to the app, when it opens new file with nano editor. I cant add images to this question, it is only a few lines of code, if you copy and paste the code and test it you will better understand the issue. just copy it and name it what you like and run it with ./Icode_demo.bash or name you choose.

I have tried this line change nano $text.bash ; cat "#!/bin/bash" >> $text.bash ;; and also this. nano $text.bash ; echo "#!/bin/bash" >> $text.bash ;;

plutesci
  • 111
  • 1
  • Welcome to Stack Overflow! Can you provide a [minimum viable concrete example](https://stackoverflow.com/help/mcve) of your problem? As it stands, people are unlikely to want to read all of your code. – jeremysprofile Jul 19 '18 at 19:36
  • I first closed this question as a duplicate of [this question](https://stackoverflow.com/questions/11162406/open-and-write-data-to-text-file-using-bash-shell-scripting/11165189) but changed my mind because it would be better to close as unclear. – that other guy Jul 19 '18 at 19:43
  • 2
    Please consider instead asking on the form "I want to write a line to a file. I tried ``cat > myfile.bash | `#!/bin/bash` `` . I expected this to write `#!/bin/bash` to the file `myfile.bash`, but instead the script hangs. How do I write a line to a file?". (So four things: Background, [MCVE](https://stackoverflow.com/help/mcve), Expected output, Actual output). This is more succinct and better suited for SO than posting "I have an issue and here's a link to my code" – that other guy Jul 19 '18 at 19:45
  • There's a commented `exec '#!/bin/bash' > test.sh` line in your script. That should probably be `echo`, not `exec`. – Barmar Jul 19 '18 at 19:52
  • BTW, you might consider fixing issues that can be found by http://shellcheck.net/ before asking questions here. (And when you *do* ask a question, be sure to follow the [mcve] rules -- meaning only the *shortest possible code* that is complete enough to produce a *specific, explicitly-described problem* should be included). – Charles Duffy Jul 19 '18 at 20:03
  • I have already used shell check and the errors it produce do not fix the issue, it only breaks the app. It works beside's me not knowing how to add the shebang! to the new bash file it creates. – plutesci Jul 19 '18 at 20:10
  • @plutesci, I promise you, fixing warnings (and adopting practices such that code you write in the future doesn't generate them in the first place) makes your code more reliable. If what seems like the obvious way to apply a fix breaks your code, the thing to do is to find the **right** way to fix that code, not to blindly ignore the warning. The code you have right now will behave very badly with filenames with spaces, for example; following shellcheck's quoting advice will fix that. – Charles Duffy Jul 19 '18 at 20:40
  • @plutesci, ...when your code has bugs that shellcheck recognizes, we recognize those bugs (we know the tool!), so it makes it look like you haven't made any effort to debug before coming here. – Charles Duffy Jul 19 '18 at 20:43
  • I don't yet have the experience in working with that. I did try. And most likely revisit it soon, thanks. – plutesci Jul 19 '18 at 20:50
  • In regards to shellcheck, I have used it to correct the errors. Thanks my original issue was my focus. It is good shellcheck. my github new version is fine – plutesci Jul 19 '18 at 21:34

1 Answers1

0

Thanks I have fixed it finally the line was this.

echo "#!/bin/bash" > $text.bash ; nano $text.bash ;;

Thanks

plutesci
  • 111
  • 1