Issue commands within script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue commands within script
# 1  
Old 10-26-2010
Issue commands within script

What is the best way of having a script that has it's own commands, which can be called at any stage in the script.
I'm sure there is a technical term for this type of CLI app which can help my search but I can't remember it.

Is using trap the best way of doing this.
# 2  
Old 10-26-2010
Is a function what your refering to?

Code:
function myfunction
{
  # your code here
}
...

function param1 param2

# 3  
Old 10-28-2010
sorry about the ambiguous title and question. Perhaps giving my specific use of this case might help, basically what I have is a script which finds all duplicates in a directory and asks "delete file?" with each set of duplicates. however during this I might find that I want to ignore all files in, say, the Mozilla directory. So I might issue a command like

> ignore "./Mozilla"

In the middle of the script. Is using trap with a function like "read...etc, case ...ignore...etc" the usual way of doing this? For example there are apps that have their own commands and their command line is prefixed by
>
is using trap to enter this mode in the middle of a script a good idea?

Last edited by cue; 11-01-2010 at 05:41 AM..
# 4  
Old 11-01-2010
No tips, anyone? I guess I'll just use trap.
# 5  
Old 11-01-2010
I do not think there is a need for trap, since you are looping through a list of files and/or directories and checking user input anyway for every delete. So instead of checking for y/n only you could check for "ignore" and take it from there.
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-01-2010
good point, that sounds even better.

There is one problem I have now though, I'm not asking for yes or no but a list of numbers that correspond to filenames in the shown set of duplicates. So I guess my follow up question is: what is the best way of checking whether the user input is a list of numbers separated by spaces, or not?
# 7  
Old 11-01-2010
You can check this with a case statement, e.g.:
Code:
case $input in)
  ignore*) bla bla 2 ;;
  *)  for i in $input
      do
        delete corresponding file or directory
      done ;;
esac

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue. I am doing some word extracting from multiline text. Interacting in CLI seems to work without issues. First step is to add multiline text to a variable. expect1.1> expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 Replies

2. Shell Programming and Scripting

Issue with running multiple commands withing su command

RHEL 6.2/Bash shell root user will be executing the below script. It switches to oracle user and expect to do the following things A. Source the environment variables for BATGPRD Database (the file used for sourcing is shown below after the script) B. Shutdown the DB from sqlplus -- The... (13 Replies)
Discussion started by: omega3
13 Replies

3. Shell Programming and Scripting

Issue with running commands from shell script

I'm trying to copy files from a remote windows server to Unix server. I was successfully able to copy files from windows server using command prompt but when I run these commands from a script it's not working as expected. commands used: sftp user@remoteserver.com lcd local_dir cd... (3 Replies)
Discussion started by: naresh7590
3 Replies

4. UNIX for Dummies Questions & Answers

Using another computer to issue commands on your own

Hey guys, I'm somewhat new to Unix and the whole terminal stuff. What I need to do is run a program that runs in the terminal window (ie I type in the program name in the window and it runs) but I have to run it from my own computer as the data is on my disk. I can connect remotely to the... (1 Reply)
Discussion started by: rsingh
1 Replies

5. Shell Programming and Scripting

Can we use aliased commands in script?

Hi All, I need a small help.. when we use aliased commands in shell script, they are not being recognized when I used. Is there any way to use aliased commands in scritping? Please let me know if u know... Thank you Chanu (19 Replies)
Discussion started by: Chanakya.m
19 Replies

6. Shell Programming and Scripting

running commands from script

I'm new to unix and I have a fairly simple problem: Lets say I am in a specific directory and I run the command: "dirs" , I get an output of all the folders that i pushed into the stack (as expected), buut, when when I create a script (called test): #! /bin/csh dirs and then i run:... (2 Replies)
Discussion started by: owijust
2 Replies

7. Solaris

Canīt issue commands as root

Hello all, I am having a problem with a Solaris 8 machine. Since 3 days ago I canīt login as root. I am able to login as a normal user and su. But as soon as I issue any command the system stop responding. If I log again as a normal user I see the process still runnig. Something I noticed,... (1 Reply)
Discussion started by: kik_xxx
1 Replies

8. Shell Programming and Scripting

Repeating commands in a script

I have written a script that I want to be repeated. The script that I wrote outputs the date, how many people are on the system, how many people logged in before me, and how many people logged in after me. Than what I want it to do is after it outputs the 4 lines I want it to go back to the... (4 Replies)
Discussion started by: Dave2874
4 Replies

9. UNIX for Dummies Questions & Answers

script commands

my bad (2 Replies)
Discussion started by: romeoz
2 Replies

10. Shell Programming and Scripting

vi Commands in a Script

Perhaps there is a better way to do this, but right now this is all I can think of. If there is a better way to do this, all suggestions are welcome. I would like to take a file and perform the following actions on it. 1. Search for CREATE TABLE 2. Copy that line and paste it one line... (7 Replies)
Discussion started by: djschmitt
7 Replies
Login or Register to Ask a Question