简体   繁体   中英

Give permission 777 for UNIX files using shell script

I want to give 777 permission for the files in UNIX and change that file as DOS file.

I want to achieve this in shellscript file. I will pass the partial file name from command prompt. Example: if the file name is employeesalary, employeejob then if i pass employee in the command prompt then all the file which starts with employee will be given access to 777 and also it needs to be changed as DOS file.

filename={$1}
chmod 777 $filename*
u2d -i $filename*

When i run the above code i am getting the below error.

chmod: WARNING: can't access employee* 

can't open employee*: No such file or directory in some location it specified 

But when i run these commands alone in command prompt its working fine

chmod 777 employee*
u2d -i employee*

There's no need for a separate variable here. Just do

chmod 777 "$1"* && u2d -i "$1"*

If you prefer it as three lines:

filename="$1"
chmod 777 "$filename"* || exit $?
u2d -i "$filename"*

That said, 777 (world-writable, world-executable) is probably not a good idea. Would 755 ( rwxr-xr-x ) or even 644 ( rw-r--r-- ) work for you? If so, that would be better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM