I did my bash like this
I did in your way Don, but when type a name of script, I used .zip extension. Should I, or just give a name? Why am I asking. Because when I wrote like this
script don't work, cause he can't move file because there is no a file like example_of_file.ZIP.C . Can you get a point? If I mv a file and add just a argument, he took and extension, but i don't want to, just a name.
It looks like you now have a working script. Here are a few comments that you may find useful in future projects:
Your earlier posts talked about copying a single file; not about unzipping a file, copying another file, and editing another file. While it is true that unzip will accept a pathname with or without the .zip extension, cp (which was in your earlier posts), mv, sed, ed, and ex require a complete filename. There are easy ways to strip off the .zip from a pathname supplied by the user using variable expansions. Using that we can let the user give the filename of the ZIP file to be processed with or without the .zip extension.
The meaning of echo -n varies from implementation to implementation and in bash depends on what options are specified when bash is started. It is easier to write portable scripts if you use printf instead of echo if the first argument to echo starts with a hyphen and if any argument to echo contains a backslash character.
Anytime you get a pathname (or any string) from a user, you should verify that a non-empty string was supplied and be prepared for the possibility that that string might contain whitespace characters. (Note that even though having spaces and tabs in filenames is legal, scripts like your fail if it tries to process those names because the references to the strings provided by the user are not quoted.)
From a human factors standpoint, the prompt give a name for script [ENTER]: sounds like you are asking for the name of a script to be executed instead of the name of a ZIP file to be processed.
You should verify that attempts to execute a command succeeded before proceeding. (For example, assuming that the ZIP file named by the user exists and the unzip command worked before trying to copy a file from a shared directory where files will be unzipped
Also note that the command:
copies the contents of that configuration file to the user's terminal with the possible removal of an octothorp from some lines in the file; but it makes absolutely no changes to the contents of that file.
Consider the following possible alternative for your script (which changes the contents of configfile.txt instead of just displaying a possibly changed version of that file on the users selected output file:
Note that some implementations of sed allow in-place editing of files (like I am doing with ed in the above script), but that option is not portable (and even if it is available on your system, many consider using it dangerous). I am only using features specified by the POSIX standards in this script (other than the absolute pathname for your shell at the start of the script) since you have not specified what operating system you're using. There are some shortcuts that could be used in bash, but I have avoided using them to make your script more portable.
I have told ed to not only update the file, but to also copy the entire contents of the updated file to standard output (to come closer to matching the output your script produced). If you don't need (or want) to see the contents of the updated file, remove the 1,$p line shown in red from the ed commands in the here-document in the script.
By changing directory to $var_dir before the unzip, we get rid of the need for the unzip -d option and speed up the unzip, mv, and ed commands slightly.
This User Gave Thanks to Don Cragun For This Post:
Hi guys,
I'm working on a large set of scripts to move files around several servers and manipulate them for our staff. Basically we're shooting things, the videos hit a server and then need organised due to the language they've been shot in. Our XML (designed for Apple's Final Cut Pro) is right... (6 Replies)
Hello,
I'm trying to write a bash script that will query the current system time (OS X 10.6.6) and then convert the output from HH:MM:SS into time in seconds. The output of the system time command (systemsetup -gettime) is returned as:
Time: HH:MM:SS
so I wanted to use awk -F: to grab... (5 Replies)
we have more then 10 jobs scheduled in cronjob.. but we can see some of the script has been changed without any notification.. can we write any script which captures any changes inside the scripts with time of change and user name like .. or any other option apart from this ??
Plz help .. (4 Replies)
Dear All,
I have many sub-folders but each of them have a file with same name but different data.
I want to either move or copy them into a new folder but they need to have the path of where they are coming as part of their name...
I have managed to find the files but dont know how to change... (2 Replies)
hi,
i want to send an email from unix using mailx command.
mailx -s "subject" "email@abc.com" < email.txt
Email.txt contains some file names that are transferred successfully and some that failed. so the files that got failed to tranfer, should be displayed in red color in the mail. is it... (1 Reply)
Hi,
I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment.
For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel"... (4 Replies)
I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows:
#!/bin/bash
HOST=$1
/usr/bin/expect -c "
spawn ssh -i /root/.ssh/id_rsa root@$HOST
expect -exact "Enter... (3 Replies)
Hi,
I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh).
I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory
" eve though I merged the whole... (7 Replies)
i have defined a function ln_s() for customizing the ln command in script1.sh.
more script1.sh
echo "Starting Execution"
./script2.sh
echo "End of Execution"
ln_s(){
] && return
ln -s "$1" "$2"
}
My script1.sh executes another script2.sh which has the following entry
more script2.sh... (12 Replies)