Okay, I have an extremely simple shell script here. It uses the string operators ## and % to separate the directory name from the filename. I'm trying to build a larger script that replaces text in files, but I can't get this part to work:
When I type source files hello/goodbye I get:Code:#!/bin/bash #script: files dire=${1%/*}; fil=${1##*/}; echo "Directory: $dire"; echo "File: $fil"; unset dir; unset fil;
Directory: hello
File: goodbye
When I type source files ~/Desktop/hello I get:
Directory: /Users/chuckboswick/Desktop
File: hello
When I type source files ~/Desktop/* I get:
Directory: /Users/chuckboswick/Desktop
File: 1226250839986du7.gif
The problem appears to be that the shell script interpreter is interpreting the string as a file path immediately after I type it. I don't want it to do that. I want it to treat it as just a plain, simple string and not recognize it as a file path. I want to eventually get a list of files by typing for file in $(ls $fil) once I'm inside the directory. How can I protect the string $1 from being immediately interpreted, but still be able to use it to list files later?


LinkBack URL
About LinkBacks




Reply With Quote







Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum