Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:06:54+00:00 2026-05-23T14:06:54+00:00

Shell script snippet: tagSearch= $(grep ‘^\#ctags$’ ./$1 | wc -l) if [[ $tagSearch -ne

  • 0

Shell script snippet:

tagSearch= $(grep '^\#ctags$' ./"$1" | wc -l)
if [[ $tagSearch -ne "0" ]]
then
    ...
fi

Results in:

line 2: /bb/bin/1: Permission denied

Context:

I’m trying to detect whether a particular pattern exists in a file so I can take a particular action.

I understand the error I’m getting, the detection is working but the script is trying to evaluate the result ‘1’ and run the program ‘1’ in my path. This isn’t what I want. How do I get the behavior I’m looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:06:54+00:00Added an answer on May 23, 2026 at 2:06 pm

    Variable assignments in the bash shell should not have a space after the equals. Actually it should never have whitespace in it at all. See below.

    tagSearch=$(grep '^\#ctags$' "./$1" | wc -l)
    if [[ $tagSearch -ne 0 ]]
    then
        ...
    fi
    

    Not important to your error but also of note, when using the double bracket syntax, you don’t need to quote that zero any more than the variable you are comparing it with.

    Actually your whole code could be re-factored using grep‘s quite mode and evaluating the return code to see if you got any matches:

    if grep '^\#ctags$' "./$1"
    then
        ...
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

do shell script cd '~/Library/Application Support/minecraft/'; if [ -d 'rezcraft_bin' ] then mv 'bin'
My shell script: #!/bin/bash if [ $# -lt 2 ] then echo $0 :
Here's a snippet of code from a shell script I have written: for src
In shell script, how do I iterate through each line in an ASCII file
I wrote a bash shell script to rename the file, #!/bin/bash #renaming the files
shell script: #!/bin/sh services=( httpd named proftpd mysqld dovecot postfix webmin) for service in
I tried the following snippet in a shell script but awk didn't find $REF
My shell script looks something like this... if [[ $uptime -lt 0 ]];then some
I have a shell script that has user execution permission on OS X, but
I have a shell script like this. line=$@ # get the complete first line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.