#!/bin/bash
# This file will fix the cygwin vs linux paths and load programmer's notepad under windows.
# mail : <[email protected]>
# 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和窗口和負載 的pn.exe [程序員在Windows記事本]之間的路徑名。所以我的問題是,殼體試驗運營商正則表達式
有「[[」或「測試」運算符的正則表達式內置。 (以及我在上述程序中使用它們的 )。但是,爲什麼如果我改變他們沒有在這裏工作,
echo $var | grep "^/*$" if [[ "$?" -eq "0" ]] ;then
此,
if [[ "$file" == ^/*$ ]] ;then
是什麼原因呢?有什麼解決方法嗎? 我已經嘗試過第二種方法
[[ "$file" == ^/*$ ]]
但它沒有工作。 然後,簡單的谷歌搜索帶給我這裏:http://unix.com/shell-programming如何找到[[operator或'test'命令的所有文檔?我已經使用
man test
但:(哪位文件規定了它的侷限性對正則表達式的使用,如果有這樣。
在先進的感謝。
的可能重複[使用中,如果正則表達式在bash中的條件](http://stackoverflow.com/que stions/2348379/use-regular-expression-in-if-condition-in-bash) – tripleee