Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer


↑ トップページへ


最近の状況


Wikiガイド(Guide)


Wiki編集用の準備ページ


サイドバー

落とし穴:Linuxのcsh事情 (2022.06,12)

Linuxのcshでは、$?$status の代わりに使えない。

  • FreeBSDでは、csh(1) は tcsh(1)へのリンク になっている。
  • で、こちらの環境では、「Variable substitution」の節に次のような記述がある。
    $?      Equivalent to `$status'. (+)
    
  • ところが、shell.osdn.net の csh(1) にはそういう記述はない。
  • なので、$? と書いてあるスクリプトは、tcsh に喰わせてやらないと undefined variable で abort してしまう。

cshが入っていない?

  • まずは、FreeBSDのサイトで検索してみる。
  • 改めて shell.osdn.net で、cshを追跡してみる。
    1. $ dir `which csh`
    2. lrwxrwxrwx 1 root root 21 329 2005 /bin/csh -> /etc/alternatives/csh*
    3. $ dir /etc/alternatives/csh
    4. lrwxrwxrwx 1 root root 12 927 2011 /etc/alternatives/csh -> /bin/bsd-csh*
    5. $ dir /bin/bsd-csh
    6. -rwxr-xr-x 1 root root 156456 718 2014 /bin/bsd-csh*
  • プロジェクトのwebサーバ でCGIを使う場合には、何と/bin/csh自体が存在しない
    1. #!/usr/bin/perl
    2. print "Status: 200 ok\n";
    3. print "Content-type: text/plain; charset=us-ascii\n";
    4. print "\n";
    5. print &get_file_info('/bin/csh') . "\n";
    6. print &get_file_info('/bin/sh' ) . "\n";
    7. exit 0;
    8. sub get_file_info()
    9. {
    10. my $file = $_[0];
    11. my @info;
    12. push @info, sprintf('%s=%d', '-f', ( -f $file ));
    13. push @info, sprintf('%s=%d', '-x', ( -x $file ));
    14. return "$file: " . join(', ', @info) . ".";
    15. }
    これをCGIとして呼び出してやると、
    /bin/csh: -f=0, -x=0.
    /bin/sh: -f=1, -x=1.
    
    という結果が返ってくる。