Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsh: command not found: sleep #1165

Open
1 task done
itsjavi opened this issue Aug 22, 2023 · 1 comment
Open
1 task done

jsh: command not found: sleep #1165

itsjavi opened this issue Aug 22, 2023 · 1 comment

Comments

@itsjavi
Copy link

itsjavi commented Aug 22, 2023

Describe the bug

The sh command "sleep" is not available in jsh

Link to the blitz that caused the error

https://stackblitz.com/~/github.com/itsjavi/storylite

Steps to reproduce

  1. Go to the console
  2. Run pnpm build

Expected behavior

jsh should provide a sleep command, and scripts using it won't fail

Parity with Local

Screenshots

No response

Platform

Version = 1.72.0
Hash = 1f5b41a1fa45587676aa81b22e70bc6505f6b12e
WebContainer = 961159ce

Browser name  = Chrome
Full version  = 115.0.0.0
Major version = 115
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
performance.memory = {
  "totalJSHeapSize": 83505079,
  "usedJSHeapSize": 79315871,
  "jsHeapSizeLimit": 4294705152
}

Additional context

While sleep is not a critical command to have, it's useful in some situations like giving enough time for the user to read the output before running next command.

It seems we have a reduced set of shell commands available:

❯ ls /bin
bash@     cp*       jsh*      ls*       ps*       rmdir*    
cat*      echo*     kill*     mkdir*    pwd*      sh@       
chmod*    hostname* ln*       mv*       rm*       zsh@   

❯ ls /usr/bin/
alias*  clear*  env*    head*   tail*   true*   which*  
cd*     curl*   false*  sort*   touch*  uptime* 

So it will be helpful to know what can be expect to be supported in the future, and what shouldn't be considered.

An example implementation of sleep (not tested):

#!/bin/sh

# check if the user provided a sleep duration
if [ $# -ne 1 ]; then
    echo "usage: sleep <seconds>"
    exit 1
fi

# calculate the end time by adding the seconds
end_time=$(($(date +%s) + $1))

# Loop until the current time is greater than or equal to the end time
while [ $(date +%s) -lt $end_time ]; do
    :
done

exit 0
@Nemikolh
Copy link
Member

Nemikolh commented Sep 4, 2023

Hey @itsjavi! This would be an excellent addition, I've added it to our internal issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants