Run .sh or shell script files using WSL in Windows 10
1. Enable WSL, refer to: https://www.shuijingwanwq.com/en/2021/12/23/9949/ , execute to step 5
3, the existing test.sh file, the code is as follows
#!/bin/bash Echo Hello World!
4. Run Windows Terminal as an administrator and execute the command: bash test.sh . run successfully. as shown in Figure 1
PS E:\wwwroot\object> bash test.sh Hello world!
5. The existing Themes.sh file, the code is as follows
#!/bin/sh for i in $(seq 1 200); do echo "install theme $i times" php artisan theme-store-db:theme:install c:/users/lenovo/downloads/theme "theme$i" Blade --force done
6. Error at runtime: syntax error near unexpected token `$\r. as shown in Figure 2
PS E:\wwwroot\object> bash themes.sh Themes.sh: line 2: $\r: command not found Themes.sh: Line 3: Syntax Error near Unexpected Token `$\r hemes.sh: line 3: `for i in $(seq 1 200); PS e:\wwwroot\object>
7. Adjust the line break in the IDE, from CRLF – Windows (\r\n) to LF – UNIX and macOS (\n). as shown in Figure 3
8. Run again, and report an error: LogicException : please make sure the php redis extension is installed and enabled. This error is an internal command executed in the file. However, executing the internal command separately, the execution is successful. as shown in Figure 4
PS E:\wwwroot\object> bash themes.sh
install theme 1 times
LogicException : please make sure the php redis extension is installed and enabled.
at /mnt/e/wwwroot/object/vendor/laravel/framework/src/illuminate/redis/connectors/phpredisconnector.php:77
73| protected function createClient(array $config)
74| {
75| return tap(new redis, function ($client) use ($config) {
76| if ($client instanceof redisfacade) {
> 77| Throw New LogicException(
78|extension_loaded(redis)
79|?Please remove or rename the redis facade alias in your "app" configuration file in order to avoid collision with the php redis extension.
80| :Please make sure the php redis extends is installed and enabled.
81| );
Exception trace:
1 Illuminate\Redis\Connectors\PhPredisConnector::Illuminate\Redis\Connectors\{Closure}()
/mnt/e/wwwroot/object/vendor/laravel/framework/src/illuminate/support/helpers.php:422
2 tap()
/mnt/e/wwwroot/object/vendor/laravel/framework/src/i lluminate/redis/connectors/phpredisconnector.php:105
Please use the argument -v to see more details.
PS E:\wwwroot\object> php artisan theme-store-db:theme:install c:/users/lenovo/downloads/theme theme --force
Install the theme to the data warehouse
The theme Theme installation was successful
PS e:\wwwroot\object>
9. The final decision is to give up running the .sh or shell script files in the WSL. Reference: Use Ubuntu to execute .sh or shell script files on Windows 10. When the redis extension of php in ubuntu, execute the command again: sh themes.sh, and report an error: redisException : connection refused. From this, it is concluded that the environment configuration on which the execution of the .sh script depends must be fully prepared in Ubuntu. The connected Redis is no longer the Redis in Windows.
PS E:\wwwroot\object> bash themes.sh
install theme 1 times
RedisException : Connection Refused
at /mnt/e/wwwroot/object/vendor/laravel/framework/src/i luminate/redis/connectors/phpredisconnector.php:137
133| $parameters[]= $context;
134| }
135| }
136|
> 137| $client->{($persistent ?pconnect:connect)}(...$parameters);
138| }
139|
140| /**
141| * create a new redis cluster instance.
Exception trace:
1 redis::pconnect()
/mnt/e/wwwroot/object/vendor/laravel/framework/src/i luminate/redis/connectors/phpredisconnector.php:137
2 Illuminate\Redis\Connectors\PhpredisConnector::establishConnection()
/mnt/e/wwwroot/object/vendor/laravel/framework/src/illuminate/redis/connectors/phpredisconnector.php:84
Please use the argument -v to see more details.
install theme 2 times
^C



