#!/bin/bash
# This file will fix the cygwin vs linux paths and load programmer's notepad under windows.
# mail : <sandundhammikaperera@gmail.com> 
# invokes the GNU GPL, all rights are granted.
# check first parameter is non empty.
# if empty then give a error message and exit.
file=${1:?"Usage: pn filename"};
if [[ "$file" == /*/* ]] ;then
  #if long directory name.
# :FAILTHROUGH:
  echo "$0: Executing pn.exe $file" 
else 
  file="$(pwd)/$file";
fi
#check whether the filename starts with / if so replace it with appropriate prefix #
prefix="C:/cygwin/";
#check for the partterns starting with "/" #
echo $var | grep "^/*$"
if [[ "$?" -eq "0" ]] ;then
  # check again whether parttern starts with /cygdrive/[a-z]/ parttern #
  if [[ $file == /cygdrive/[a-z]/* ]] ; then 
    file=${file#/cygdrive/[a-z]/};
    file="C:/"$file;
  else
    file="$prefix""$file";  
  fi 
fi
#check for the appropriate file permissions #
# :TODO: 
echo $file
exec "/cygdrive/c/Program Files (x86)/Programmer's Notepad/pn.exe"  $file 
私のプログラムでは、cygwin と Windows の間でパス名を変換し、pn.exe [Windows のプログラマーのメモ帳] をロードします。だから私の質問は、
- "[[" または 'test' 演算子の正規表現が組み込まれています。(上記のプログラムでそれらを使用したのと同様に)。しかし、私が変わったら、なぜ彼らはここで働かないのか、 - echo $var | grep "^/*$" if [[ "$?" -eq "0" ]] ;then- これに、 - if [[ "$file" == ^/*$ ]] ;then- その理由は何ですか?回避策はありますか?2 番目の方法は既に試しました - [[ "$file" == ^/*$ ]]が、うまくいきませんでした。次に、簡単なグーグルが私にここにもたらしました:http://unix.com/shell-programming
- [[ 演算子または 'test' コマンドに関するすべてのドキュメントを見つける方法は? 私は使用 - man testしましたが:(。正規表現の使用に関する制限がある場合、そのドキュメントはそれを指定しています。