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

./myyt: 9: Syntax error: redirection unexpected #2

Closed
StereoFox opened this issue Dec 27, 2020 · 4 comments
Closed

./myyt: 9: Syntax error: redirection unexpected #2

StereoFox opened this issue Dec 27, 2020 · 4 comments

Comments

@StereoFox
Copy link

StereoFox commented Dec 27, 2020

Hi Bugswriter, thanks for the script!

When running ./dmenyt or ./myyt it prompts for the search query. Regardless of what I enter I receive the syntax error

$ ./myyt
Search query: test
./myyt: 9: Syntax error: redirection unexpected

Dependencies:

fzf is already the newest version (0.20.0-1).
mpv is already the newest version (0.32.0-1ubuntu1).
suckless-tools is already the newest version (44-1). [This contains dmenu]
youtube-dl is already the newest version (2020.03.24-1).

API key is properly inserted as variable in terminal,
output of echo:

user@desktop$: echo $YT_API_KEY
AIzaSyB-rGfbeC2w8dMxxxxxxx
@slavistan
Copy link

slavistan commented Dec 27, 2020

The error is due to the usage of the here-string construct (<<<) in line 9: query="$(sed 's/ /+/g' <<<$query)". Presumably @Bugswriter links /bin/sh to bash whereas some people use a strictly POSIX compliant shell. Since the here-string is a bashism and not POSIX compliant this script will fail for the latter.

To fix the issue either change the executing shell to #!/bin/bash, or pipe in the input using query="$(echo "$query" | sed 's/ /+/g')" or use the POSIX-compliant heredoc construct:

query="$(sed 's/ /+/g' <<EOF
$query
EOF
)"

Herestring is simply syntactic sugar for single-line heredoc input.

@Bugswriter
Copy link
Owner

Bugswriter commented Dec 27, 2020 via email

@Bugswriter
Copy link
Owner

Bugswriter commented Dec 27, 2020 via email

@StereoFox
Copy link
Author

That worked, thanks!

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

No branches or pull requests

3 participants