Results 1 to 2 of 2

Thread: gedit external tool

  1. #1
    Join Date
    Aug 2018
    Beans
    1

    gedit external tool

    I have setup a script in gedit external tool given below. The tool executed for example on a "test.c" file does not respect the "py" matching and executes python compile command anyway.
    Kindly guide me on this matter.
    Code:
    #!/bin/sh
    file=${GEDIT_CURRENT_DOCUMENT_NAME%}
    ext=${file##*.}
    if [ "$ext"=="py" ]; then
    python  $file
    else
    printf "A C file"
    fi

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: gedit external tool

    Hello and welcome to the forums

    The issue is with your test bracket I think. The POSIX form is

    Code:
    if [ "$ext" = "py" ]; then
    Note in particular the whitespace around the operator - otherwise you are testing the single (string) argument "$ext"=="py" (which will always be true)

    You could also consider using a case:

    Code:
    case $ext in
      py) python  "$file"
      ;;
      *) printf "A C file\n"
      ;;
    esac
    Last edited by steeldriver; August 23rd, 2018 at 09:24 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •