1. Enable WSL, refer to: Execute up to step 5
3. There is an existing test.sh file, its code is as follows
#!/bin/bash
echo Hello World!
4. Run Windows Terminal as an administrator, and execute the command: bash test.sh. It runs successfully. As shown in Figure 1

PS E:\wwwroot\object> bash test.sh
Hello World!
5. There is an existing themes.sh file, its 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. An error occurs 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 endings in the IDE from CRLF – Windows (\r\n) to LF – Unix and macOS (\n). As shown in Figure 3

8. Run it again, and an error occurs: LogicException : Please make sure the PHP Redis extension is installed and enabled. This error is triggered by an internal command executed within the file. However, executing the internal command separately succeeds. 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 extension 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/Illuminate/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 blade --force
安装主题到数据仓库
主题theme安装成功
PS E:\wwwroot\object>
9. Finally, I decided to give up running .sh or Shell script files in WSL. Reference: Running .sh or Shell script files using Ubuntu on Windows 10. After installing the PHP Redis extension in Ubuntu, executing the command sh themes.sh again results in an error: RedisException : Connection refused. This leads to the conclusion that the environment configurations required for executing .sh scripts must be fully prepared in Ubuntu. The Redis being connected to 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/Illuminate/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/Illuminate/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
