Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Problem insert $1 value into a command Post 302560530 by PatMcDonagh on Friday 30th of September 2011 04:52:53 AM
Old 09-30-2011
[Solved] Problem insert $1 value into a command

Hi folks

I am trying to use a call to a python command within a shell script to help validate a date. If I hard code the date to be checked in the string it works. As follows

Code:
 
cmd_result=$(/usr/bin/python -c 'import time; print time.strftime("%d",time.strptime("31/02/2008", "%d/%m/%Y"))' \
 2>/dev/null | wc -l)
if [ ${cmd_result} -eq 0 ]; then
    echo "Date Invalid "
else
    echo "Date Valid"
fi

If i use $1 instead, i.e. passing the date as an input paramater (e.g ./sysReport.sh 23/04/2011), I cant seem to get the value in $1 to be picked up by the command. I am using the following.

Code:
 
datein=$1
cmd_result=$(/usr/bin/python -c "import time; print time.strftime('%d',time.strptime('" ${datein} "', '%d/%m/%Y'))" \
 2>/dev/null | wc -l)
if [ ${cmd_result} -eq 0 ]; then
    echo "Date Invalid "
else
    echo "Date Valid"
fi

I know that datein stores the value of the input parameter $1 but the execution of the python command always returns zero for valid or invalid dates.

I kow I am not using the reference to the ${datein} or $1 varaiable correctly but have tried numerous mechanisms without any joy.

I can easily just some code from the web that validates a date but this is more about why i cant seem to execute the python command and why i cant insert the contents of a variable into the command.

Any help explaining this or helping to find a solution would be appreciated.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

2. AIX

Problem Solved

Generally, most people, I guess, go from 5.3 ML4 Directly to TL 7. So they may never run into this issue. For the rest of us, here is the resolution of my problem in going from ML6 to TL7. Apparently with the change from ML to TL IBM added a "BuildDate Verification" routine into... (1 Reply)
Discussion started by: mrmurdock
1 Replies

3. OS X (Apple)

keyboard problem how to insert --> {} \

I have MACOSX Leoparad and MacBook Pro but I am unable to insert the above letters when I am in terminal any help please? e.g. to insert them I need to press alt+shift+) == } but if I do so pressing alt+shift+) nothing works :( ---------- Post updated at 03:54 AM ---------- Previous update was... (2 Replies)
Discussion started by: c_lady
2 Replies

4. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

5. UNIX for Dummies Questions & Answers

[Solved] execution problem

Hi I want to make a script . In this script i want to use input file and this input file consist of three numbers in a line for example input file is as below: 919876543210 09876543234567876 98764534245678 aircelmms","aircelweb","aircelwap" 096574235625... (2 Replies)
Discussion started by: esumiba
2 Replies

6. Solaris

Execution problem in shell script while insert into DB

Hi, am facing some problem while inserting a record into a script Please find script below. `sqlplus -s asdf/asdf123 <<eof! set feedback off; set heading off; set verify off; insert into... (2 Replies)
Discussion started by: senkerth
2 Replies

7. UNIX for Advanced & Expert Users

Insert Command Creating Table Locking Problem

Hi, i have a java based tool which does insert operation in a TABLE, and in parallel the same table is used by my C++ code which does select Query. the Table will be always busy, but sometimes the table is getting locked when i try to make an insert, am bit confused whether the lock is... (9 Replies)
Discussion started by: senkerth
9 Replies

8. Shell Programming and Scripting

[Solved] Problem with if-then-else loop

Hi, i have a problem with this script: for i in $(cat list_ip_switch) do if if ; then echo "found ip" else echo "not found ip" fi done cat list_ip_switch 10.155.249.171 10.155.249.172 (3 Replies)
Discussion started by: elilmal
3 Replies

9. UNIX for Dummies Questions & Answers

[Solved] Problem With "xhost +" command-FreeBSD

Does anyone no why "xhost +" would not be working in freebsd? Could it be to do with a certain xorg package not being installed etc.. I am getting error "xhost: command not found" Thanks Anyone (2 Replies)
Discussion started by: Browser
2 Replies

10. Shell Programming and Scripting

[Solved] Insert tabs as delimiter

Hello all, I have an unstructured file with space as delimiter , which I want to structure. The output file should actually have only 5 columns with tab as delimiter. The 4th column can have only 3 values ( biological_process , cellular_component , molecular_function ) Here is how the... (12 Replies)
Discussion started by: ritakadm
12 Replies
platform::shell(3tcl)					       Tcl Bundled Packages					     platform::shell(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
platform::shell - System identification support code and utilities SYNOPSIS
package require platform::shell ?1.1.4? platform::shell::generic shell platform::shell::identify shell platform::shell::platform shell _________________________________________________________________ DESCRIPTION
The platform::shell package provides several utility commands useful for the identification of the architecture of a specific Tcl shell. This package allows the identification of the architecture of a specific Tcl shell different from the shell running the package. The only requirement is that the other shell (identified by its path), is actually executable on the current machine. While for most platform this means that the architecture of the interrogated shell is identical to the architecture of the running shell this is not generally true. A counter example are all platforms which have 32 and 64 bit variants and where a 64bit system is able to run 32bit code. For these running and interrogated shell may have different 32/64 bit settings and thus different identifiers. For applications like a code repository it is important to identify the architecture of the shell which will actually run the installed packages, versus the architecture of the shell running the repository software. COMMANDS
platform::shell::identify shell This command does the same identification as platform::identify, for the specified Tcl shell, in contrast to the running shell. platform::shell::generic shell This command does the same identification as platform::generic, for the specified Tcl shell, in contrast to the running shell. platform::shell::platform shell This command returns the contents of tcl_platform(platform) for the specified Tcl shell. KEYWORDS
operating system, cpu architecture, platform, architecture platform::shell 1.1.4 platform::shell(3tcl)
All times are GMT -4. The time now is 06:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy