Question about Variables in If?


 
Thread Tools Search this Thread
Operating Systems Linux Question about Variables in If?
# 1  
Old 05-16-2010
Question about Variables in If?

Hi everybody, im trying to store a path "address" of a file in a variable, then IF the Address that the user entered INSIDE the variable is exist, do something, else echo invalid file address.

here's my code, but it's not working i dunno why:

Code:
$variable
cat > variable
#variable will contain the Adress of the file i want to check if exist or not.
if [ -e "$variable" ]
then
COMMANDS
else
echo "the file is not exist!!"
fi


Please please i need the answer immidiatly, if any one can help..
thank you all Smilie

Last edited by DukeNuke2; 05-16-2010 at 09:52 AM..
# 2  
Old 05-16-2010
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
# 3  
Old 05-16-2010
Quote:
Originally Posted by iam_ako
Code:
echo -n "Enter full path of a file: "
read variable
if [ -e "$variable" ]
then
COMMANDS
else
echo "the file is not exist!!"
fi

# 4  
Old 05-16-2010
The logic in your code seems flawed. I would suggest you do this
Code:
if [ -z $variable ]
echo "The variable is not set"
elseif
$variable = "/path/to/place"
do
something
fi

# 5  
Old 05-17-2010
Well, pseudocoder i cant say how im greatful for ur effort..
you're a great man really thank u very much.. thank god it works finally
mark54g thank you too for ur help..

thanks guys really ur great Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Question On Sourcing Variables

I have 2 scripts first script would call second script. test1.sh #!/bin/bash logfile=`basename $0`.log echo "First File" >> $logfile TIME=`ls -lu array.ksh | awk '{print $6" "$7" "$8}'` . /home/infrmtca/bin/Test/test2.sh #/home/infrmtca/bin/Test/test2.sh test2.sh #!/bin/bash... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

awk question for printing variables

Hi All, I have the following awk code where I am passing 4 variables to the program and I need to print them in the awk script. The variables are $start_month $start_date - $end_month $end_date. printf("\tFor More Information\n") > out_tmp1 printf("\tIf you have any questions about this... (6 Replies)
Discussion started by: nua7
6 Replies

3. Programming

Question on integer variables (c++)

Hello guys! It's orszhak and in my book I am currently studying incrementing values in c++ and it states thant I could do this to increment the value of nVariable nVariable = nVariable + 2; it states that I could also do this and assign the same value nVariable += 2; but can't I also do this and... (1 Reply)
Discussion started by: orszhak
1 Replies

4. UNIX for Dummies Questions & Answers

Variables question

Hi I am trying to find were to look for definitions of these variables; $0, $1, $2, $#, $$ , $*. I am not having much luck with my searching. Can anyone point me in the right direction? Thanks, Doug (3 Replies)
Discussion started by: Reddoug
3 Replies

5. Shell Programming and Scripting

Question about variables

What does this mean? #!/bin/bash BACKUPFILE=backup-$(date +%m-%d-%Y) archive=${1:-$BACKUPFILE} (4 Replies)
Discussion started by: hin-linux
4 Replies

6. Shell Programming and Scripting

question about variables with sed

Hi, I am trying to do some mass replacements in lots of scripts, and using sed. However sed doesn't seem to like to be able to dereference variables within the substitute clause. For example: tab=newtable cat f1 | sed 's/oldtable/$tab/g' doesn't work. it would replace oldtable with the... (2 Replies)
Discussion started by: fwellers
2 Replies

7. UNIX for Dummies Questions & Answers

Shell script question on variables

I have the following script that is supposed to calculate the runtime of the script as a whole (edited for brevity): #!/bin/sh # set endtime and print elapsed time set starttime=`date +%s` echo "Value of starttime: " $starttime sleep 1 set endtime=`date +%s` echo "Value of endtime: "... (2 Replies)
Discussion started by: figaro
2 Replies

8. UNIX for Dummies Questions & Answers

Question about variables

I am looking for 8 variables in the following profile. I am looking to see if anyone could explain this for me better than the book I am using has been able to. There are 5 system, 2 aliases, and one editor. The profile is as follows: # @(#)local.profile 1.8 99/03/26 SMI stty istrip... (0 Replies)
Discussion started by: wswaner
0 Replies

9. Programming

A question on C programming and Outputing variables

I was wondering if someone could show me what I'd need to do in C programming language to output the current values of all of your environment variables and do so in such a way that it will duplicate an "env" command on unix. Does anyone know how and can you share it with me? Thanks in advance. (2 Replies)
Discussion started by: HelpMeIAmLost
2 Replies

10. Shell Programming and Scripting

Question variables Korn

I'm using the following command to test for certain characters in a script echo "${1}" | grep '\$' if (( ${?} == 0 )) then testing this script on the command line I have ksh -x script1.sh "xxxx$xxxx" this works fine but when I want to use ksh -x script1.sh "xxxx $xxx" the... (1 Reply)
Discussion started by: frank
1 Replies
Login or Register to Ask a Question