code: def _expand_path(s: str) -> str:
      """Expand $VARS and ~names in a string, like a shell
  
      :Examples:
  
         In [2]: os.environ['FOO']='test'
  
         In [3]: expand_path('variable FOO is $FOO')
         Out[3]: 'variable FOO is test'
      """
      # This is a pretty subtle hack. When expand user is given a UNC path
      # on Windows (\\server\share$\%username%), os.path.expandvars, removes
      # the $ to get (\\server\share\%username%). I think it considered $
      # alone an empty var. But, we need the $ to remains there (it indicates
      # a hidden share).
      if os.name == "nt":
          s = s.replace("$\\", "IPYTHON_TEMP")
      s = os.path.expandvars(os.path.expanduser(s))
      if os.name == "nt":
          s = s.replace("IPYTHON_TEMP", "$\\")
      return s
  
imports: from __future__ import annotations
  import os
  from typing import Sequence
  from jupyter_core.utils import ensure_async, run_sync
  from .session import utcnow
label_desc: Use image node_id 2 for calling a global function with example usage: _expand_path(s) and returns: s