Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Bash: Getting variable directory name for directory which contains spaces and a single quote

  • 29-07-2022 2:10pm
    #1
    Registered Users, Registered Users 2 Posts: 5,659 ✭✭✭


    Here is an example directory

    drwxr-xr-x 1 vangryman 197121 0 Jul 29 13:27 "2022-07-29 13.26.09 Very Angryman's Personal Meeting Room"/


    So i'm trying to get the directory name to later cd into it


    $ cat get_zoom.sh

    #!/bin/bash

    dir=$(ls -tr ../../Downloads/Documents/Zoom/ | tail -1)

    cd "\"\"$dir\"\""

    pwd



    But no joy with how i wrap quotes


    $ sh -x get_zoom.sh

    ++ ls -tr ../../Downloads/Documents/Zoom/

    ++ tail -1

    + dir='2022-07-29 13.28.21 Very Angryman''\''s Personal Meeting Room'

    + cd '""2022-07-29 13.28.21 Very Angryman'\''s Personal Meeting Room""'

    get_zoom.sh: line 3: cd: ""2022-07-29 13.28.21 Very Angryman's Personal Meeting Room"": No such file or directory



Comments

  • Registered Users, Registered Users 2 Posts: 14,206 ✭✭✭✭Igotadose


    Does cd "${dir}" work any better? I think your \"\" wrapper is what's messing it up.



  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


     cd "$(/bin/ls -tr  ../../Downloads/Documents/Zoom/ | tail -1)"
    

    Works here



  • Registered Users, Registered Users 2 Posts: 5,659 ✭✭✭veryangryman


    Thanks guys got sorted

    zoom_path="/c/Users/$(whoami)/Downloads/Documents/Zoom/"

    cd "${zoom_path}""$(ls -tr ${zoom_path} | tail -1)"



Advertisement