holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.69k stars 117 forks source link

Is it possible to run shell scripts in A-shell? #503

Open YousufSSyed opened 1 year ago

YousufSSyed commented 1 year ago

I want to have bash commands in a .sh file and run them by entering in ./shell-script.sh

holzschu commented 1 year ago

The good news is: you can run shell scripts in a-Shell. If you create a file, and it begins with #! sh or #! /bin/sh (to tell the system that it's a shell script, not a Lua, Python or Perl script), and set the executable bit with chmod -x file, then it will be executed when you type ./file.

The bad news is: it's a sh script (more precisely, dash), not a bash script, because bash is covered by the GPL. Bash advances features are not available, but a lot of things are present.

YousufSSyed commented 1 year ago

So I got a shell script working by doing sh ~/path/to/script.sh in case anyone else is reading this.

And here are some other things I started thinking about:

holzschu commented 1 year ago
YousufSSyed commented 1 year ago

@holzschu Oh can you see that I mentioned at the NewTerm repo? Well I'm wondering how Zsh and Bash can work in NewTerm but not A-shell. Maybe it has to do with NewTerm running on jailbroken devices?

holzschu commented 1 year ago

If you're running on a jailbroken device, then you're not distributing on the AppStore, so the restriction from the FSF does not apply (their problem is specifically with the distribution on the AppStore). Also, on a jailbroken device, you have access to fork() and exec() and all the other functions, so you can actually compile on the device and distribute the binaries. It's much easier. I started this project specifically because I wanted to have the same kind of functionality without having to jailbreak. As you have seen, there are still differences, but it's getting there: one year ago, there were no shells at all, now we have dash.

YousufSSyed commented 1 year ago

Do you mean compile on or for the device? Can you elaborate?

holzschu commented 1 year ago

With a jailbroken device, you have a compiler like gcc installed on your device, so you can actually compile new commands on the device, for the device.

YousufSSyed commented 1 year ago

Couldn't you use the same flags and commands to compile Bash and Zsh for iOS on Mac, as you would on a jailbroken iOS device? Is compiling for iOS devices device specific, so if it compiles on one iOS device it doesn't mean it can compile on another, for whatever reasons?

holzschu commented 1 year ago

I don't understand your question. Cross-compiling (compiling on one platform for another) is always difficult. There are no shortcuts. It's not the same platform, it's not the same flags. Many compile scripts assume that you can run the binaries that you just created, which is impossible here. On top of that, there are all the specificities of iOS to consider: since there is no fork/exec, I need to clear up memory when the program leaves. There is no stdout, so I have to rewrite output functions. I also have to rewrite parts of the command that call other commands and so on.

YousufSSyed commented 1 year ago

Ok. I took a look at the Discord server but didn't find it in the readme, I had to search "Discord" in the whole repo to get the server link since I never saw it mentioned elsewhere before that. Why don't you add an FAQ section in the readme or make a repo wiki?

Or at least put the link to the Discord in the readme?

miron commented 1 year ago
  • There is a Discord server, whose address you can find in the "help" command inside a-Shell, where we discuss these things.

I don’t think it can be more clear than that.

CarlGao4 commented 1 year ago

I want to ask that is it possible to compile some applications and distribute them in https://github.com/holzschu/a-Shell-commands ?

holzschu commented 1 year ago

Absolutely!

CarlGao4 commented 1 year ago

Sorry that my spell checker replaced the wrong word for me ... I wanted to ask that is it possible to compile bash and distribute it using https://github.com/holzschu/a-Shell-commands ?

holzschu commented 1 year ago

a-Shell-commands is for commands that have been compiled into WebAssembly (commands compiled into Arm64 binaries, such as dash, have to be distributed with the app itself). As of today, WebAssembly can only be used for simple commands. A fully working shell like bash is way too complicated for it.

CarlGao4 commented 1 year ago

commands compiled into Arm64 binaries, such as dash, have to be distributed with the app itself

But why?

holzschu commented 1 year ago

That is the entire principle of Apple's AppStore: to protect users, all the binary content of the app must be submitted to the review process. It is not possible to add more binary content to an app after it has been approved for distribution. This is both a legal interdiction, and a physical interdiction: binaries are stored in a separate place and encrypted.

The good news is: once an app has been approved, as a user you're pretty sure that it won't do something forbidden, like steal your personal data. The bad news is: it's very hard to add functionalities to an existing app. WebAssembly binaries get an exception, just like x86 binaries for iSh, because technically they aren't "binaries", in the sense that they cannot be executed by the phone.

CarlGao4 commented 1 year ago

Thanks for your explanation! Just like what I met when binding macOS .app applications, after I sign it, the program will refuse to run if I add more files into it