Issue
Hello is this possible to create a file with these line of codes below and make it as an executable file on single line of code? Currently I'm doing manually. Your response is highly appreciated. Thank you
Manual Steps
-vi + content
-chmod +x filename
This is the file content:
#!/bin/bash
sudo apt-get update
sudo apt install curl -y
sudo apt install -y default-jdk
Screenshot:
Objective to write everything using one line of code
Solution
If it is crucial that it be a one-liner and vi is not a requirement:
echo -e '#!/bin/bash\nsudo apt-get update\nsudo apt install curl -y\nsudo apt install -y default-jdk' > test.sh && chmod +x test.sh && ./test.sh
If vi is a requirement you could do something like:
vim file.txt "+i#!/bin/bash" "+osudo apt-get update" "+o..." and so on
in place of the echo, but this seems much less effective to me and I'm less familiar with using vi in this way.
Answered By - sea0003 Answer Checked By - Cary Denson (WPSolving Admin)