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
2
Answers
You could generate a
test.sh
with bash script (we can call itdownload.sh
):When you execute
bash download.sh
, it will generate atest.sh
automatically.If it is crucial that it be a one-liner and vi is not a requirement:
echo -e '#!/bin/bashnsudo apt-get updatensudo apt install curl -ynsudo 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.