problem in creating execute profile file in unix

first i created a profile file(my_var.profile) which contains

export my_var=20

after that i created shell scripts(my_var.sh) which contains

#!/bin/bash
. ./my_var.profile
echo '$my_var='$my_var

but when i am executing sh my_var.sh it is showing error that no such file/directory .profile.

correct as below

./my_var.profile
echo "my_var=$my_var"

again it is showing same error no such file or directory.profile

Try sh ./my_var.sh

snapshot of error message

https://picasaweb.google.com/105463293573243221698/February42012?authuser=0&feat=directlink

I noticed you are using cygwin. Can it be that your files have been created in dos format and they end with carriage return-line feed. If so your second file is trying to source ./my_var.profile<CR>, which would also account for the strange error message (after a carriage return it writes on the same line). I would remove the CR characters (for example by a dos to unix command) and try again..

1 Like

give full permission for the file i.e

chmod 777 my_var.profile

and run using

sh my_var.sh