Home>

I want to register the following command to alias or function with WSL bash (ubuntu bash), but it doesn't work. What should I do?

powershell.exe. $(python -c "import os.path;print os.path.relpath ('/ mnt/c/_videos/agd/$(ls -t1/mnt/c/_videos/agd/| head -n 1) ',' $(echo $PWD) ') ")
Tried

alias

alias agd = 'powershell.exe. $(python -c "import os.path;print os.path.relpath ('/mnt/c/_videos/agd/$(ls -t1/mnt/c/_videos/agd/| head -n 1) ',' $(echo $PWD) ') ")'


Error

$agd
  File "<string>", line 1
    import os.path;print os.path.relpath (/mnt/c/_videos/agd/video_20180824_104256.mp4,/mnt/c/_images)
                                          ^
SyntaxError: invalid syntax
At line: 1 char: 1
+.
+ ~
Missing expression after '.' In pipeline element.
    + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId: MissingExpression


Function

agd () {
  powershell.exe. $(python -c "import os.path;print os.path.relpath ('/ mnt/c/_videos/agd/$(ls -t1/mnt/c/_videos/agd/| head -n 1) ',' $(echo $PWD) ') ")
}


Error

bash: syntax error around unexpected token `} '
  • Answer # 1

    It seems like you don't understand how to use quotes.

    alias agd = "powershell.exe. \ $(python -c \" import os.path;print os.path.relpath ('/ mnt/c/_videos/agd/\ $(ls -t1/mnt/c/_videos/agd/| head -n 1) ',' \ $(echo \ $PWD) ') \ ")"
    Or
    alias agd = 'powershell.exe. $(python -c "import os.path;print os.path.relpath (' \ ''/mnt/c/_videos/agd/$(ls -t1/mnt/c/_videos/agd/| head -n 1) '\' ',' \ '' $(echo $PWD) '\' ') ")'
    The

    function looks good.

    Although it is not a mistake,$(echo $PWD)is the same as$PWDandos.path.relpath Since the default of the second argument ofis the current directory, the second argument is unnecessary in the first place.

  • Answer # 2

    It may not be related to the error, but
    Since powershell.exe is a Windows command, Linux paths in the/mnt/c/format are accepted m
    wslpath -w/mnt/c/...
    Needs to be converted to Windows format.