Skip to content

Instantly share code, notes, and snippets.

@tylergaw
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save tylergaw/6a24da1bbb0716513cc2 to your computer and use it in GitHub Desktop.

Select an option

Save tylergaw/6a24da1bbb0716513cc2 to your computer and use it in GitHub Desktop.
Passing quoted string of directory name as an argument
I'm calling the shlelfish.sh script below from Objective-C's NSTask. It has an arguments property. That property is an Array. I need to include
the name of a directory in that array and it needs to be a string; single or double-quoted. When the string of the directory
name is passed to the script it seems like it's equivilent to the following:
./shelfish.sh "~"
ls: ~: No such file or directory
Each time I try with either ls or cd or the command I actually need to run which requires a directory it fails with the same error.
Is there a good way to strip the quotes or am I just trying to do something bone-headed?
#!/bin/sh
# Shell Script attempts to display list the contents of the first argument given
ls $1
@tylergaw
Copy link
Copy Markdown
Author

tylergaw commented Aug 9, 2014

Also isn't the actual script. Just wanted to get it down to the smallest example possible.

@grayrest
Copy link
Copy Markdown

grayrest commented Aug 9, 2014

#!/bin/sh

ls $($1)

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