Sponsored Content
Top Forums Shell Programming and Scripting help needed with script that gets a filename as argument (with an if/else statement) Post 302302888 by I-1 on Wednesday 1st of April 2009 09:30:48 AM
Old 04-01-2009
help needed with script that gets a filename as argument (with an if/else statement)

Hi,

I am trying to create a script just to study BASH scripting, but I have some problems.

I need to create a script that gets a filename as an argument. The script should behave as follows:
• If the given file name already exists, inform the user and quit.
• If the given file name does not exist, create an empty file by that name and inform the user.

This is my start:

Code:
#!/bin/sh
echo "type in a filename:"
read $FILENAME

if 

....

else

#filename that does not exist is created
echo "The filename $FILENAME does not exist, creating empty file $FILENAME"
touch $FILENAME

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

pass argument to a filename

How can I use the value of an argument as a filename? Example: The argument for a process is 999. I would like the output of the process to be placed in a file called 999. I have tried using $$1, but that only assigns a unigue number. thanks JP (1 Reply)
Discussion started by: jpprial
1 Replies

2. Shell Programming and Scripting

help needed in using case statement

Hi, I have a script as below: ....................................................................... rpttxt() { name="$*" awk '/'"${name}"'/ {print $2$3$4 }' file_1.txt } title="`rpttxt "TITLE"`" ......................................................................... The... (0 Replies)
Discussion started by: jisha
0 Replies

3. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

4. Shell Programming and Scripting

use input filename as an argument to name output file

I know this is a simple matter, but I'm new to this. I have a shell script that calls a sed script from within it. I want the output of the shell script to be based on the input file I pass as an argument to the original script. In other words... ./script.sh file.txt (script.sh calls sed... (2 Replies)
Discussion started by: estebandido
2 Replies

5. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

6. Shell Programming and Scripting

filename change with awk needed

Hi, i have files which contains list of csv file names say temp.txt contains below like data Dns_bangalore_08172011.093033.1139.csv Dns_bangalore_08172011.093133.1139.csv now i want to insert some string before .csv in the filename say i want to insert string _sim1 beofre .csv... (3 Replies)
Discussion started by: raghavendra.nsn
3 Replies

7. Shell Programming and Scripting

How to pass a filename as a command line argument

Hi,I have a script which is given below :#!/bin/bash. ini_script.shdb2 connect to $DB_NAME user $DB2_UID using $DB2_PASSWORDfor file in `ls -1 ./sql/ddw/`do echo "Executing the file $file" echo db2 -tvf $filedonedb2 quiti want this script to accept directorie's names present in... (1 Reply)
Discussion started by: ektubbe
1 Replies

8. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

9. Shell Programming and Scripting

bash if statement help needed

Hi I need a script with an if statement that goes. I need it to search through all files within a directory with the extension .test if it finds the string '71502FSC1206' then do sed 's/71502FSC1206/\n&/g' > send.test If it finds the string '715MCH' or '715JAC' then I need it to move the... (1 Reply)
Discussion started by: firefox2k2
1 Replies

10. Programming

Python passing filename through argument

Hello, A python beginner question on passing filename thru argument. My code is: #!/usr/bin/python import sys, getopt import os def main(argv): try: opts, args = getopt.getopt(sys.argv,"hi:o:ce", ) except getopt.GetoptError: usage() print("Usage: %s... (6 Replies)
Discussion started by: yifangt
6 Replies
dbus-uuidgen(1) 					      General Commands Manual						   dbus-uuidgen(1)

NAME
dbus-uuidgen - Utility to generate UUIDs SYNOPSIS
dbus-uuidgen [--version] [--ensure[=FILENAME]] [--get[=FILENAME]] DESCRIPTION
The dbus-uuidgen command generates or reads a universally unique ID. Note that the D-Bus UUID has no relationship to RFC 4122 and does not generate UUIDs compatible with that spec. Many systems have a sepa- rate command for that (often called "uuidgen"). See http://www.freedesktop.org/software/dbus/ for more information about D-Bus. The primary usage of dbus-uuidgen is to run in the post-install script of a D-Bus package like this: dbus-uuidgen --ensure This will ensure that /var/lib/dbus/machine-id exists and has the uuid in it. It won't overwrite an existing uuid, since this id should remain fixed for a single machine until the next reboot at least. The important properties of the machine UUID are that 1) it remains unchanged until the next reboot and 2) it is different for any two run- ning instances of the OS kernel. That is, if two processes see the same UUID, they should also see the same shared memory, UNIX domain sockets, local X displays, localhost.localdomain resolution, process IDs, and so forth. If you run dbus-uuidgen with no options it just prints a new uuid made up out of thin air. If you run it with --get, it prints the machine UUID by default, or the UUID in the specified file if you specify a file. If you try to change an existing machine-id on a running system, it will probably result in bad things happening. Don't try to change this file. Also, don't make it the same on two different systems; it needs to be different anytime there are two different kernels running. The UUID should be different on two different virtual machines, because there are two different kernels. OPTIONS
The following options are supported: --get[=FILENAME] If a filename is not given, defaults to localstatedir/lib/dbus/machine-id (localstatedir is usually /var). If this file exists and is valid, the uuid in the file is printed on stdout. Otherwise, the command exits with a nonzero status. --ensure[=FILENAME] If a filename is not given, defaults to localstatedir/lib/dbus/machine-id (localstatedir is usually /var). If this file exists then it will be validated, and a failure code returned if it contains the wrong thing. If the file does not exist, it will be created with a new uuid in it. On success, prints no output. --version Print the version of dbus-uuidgen AUTHOR
See http://www.freedesktop.org/software/dbus/doc/AUTHORS BUGS
Please send bug reports to the D-Bus mailing list or bug tracker, see http://www.freedesktop.org/software/dbus/ dbus-uuidgen(1)
All times are GMT -4. The time now is 06:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy