# shell script help please

**URL:** <https://community.unix.com/t/shell-script-help-please/277215>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [November 11, 2010, 11:01pm UTC](https://community.unix.com/t/shell-script-help-please/277215 "2010-11-11T23:01:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iluvsushi](https://community.unix.com/letter_avatar/iluvsushi/32/6_449c533f586939b6e5f246632a46421f.png) [@iluvsushi](https://community.unix.com/u/iluvsushi)\
**Post date:** [November 11, 2010, 11:01pm UTC](https://community.unix.com/t/shell-script-help-please/277215/1 "2010-11-11T23:01:30Z")

</div>

```nohighlight
#!/bin/bash

x = `find / -type f -inum +1 -mtime -30 -exec ls -lu {} \; 2>/dev/null | awk '{print $6,$7,$8}'`

y = `find / -type f -inum +1 -mtime -30 -exec ls -lc {} \; 2>/dev/null | awk '{print $6,$7,$8}'`

z = `find / -type f -inum +1 -mtime -30 -exec ls -lc {} \; 2>/dev/null | awk '{print $9}'`

echo "$x $y $z"

```

i don't understand why i do not get an output.  
when i execute these commands in the shell, they work perfectly but when i assign them a variable and do echo to print the variables, no output when i execute the shell. the shell waits for command to end.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_449c533f586939b6e5f246632a46421f.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [November 11, 2010, 11:11pm UTC](https://community.unix.com/t/shell-script-help-please/277215/2 "2010-11-11T23:11:23Z")

</div>

You cannot have variable[space] = [space] `code here `

Remove all spaces around the =

---

<div class="post-metadata">

**Author:** ![iluvsushi](https://community.unix.com/letter_avatar/iluvsushi/32/6_449c533f586939b6e5f246632a46421f.png) [@iluvsushi](https://community.unix.com/u/iluvsushi)\
**Post date:** [November 12, 2010, 12:22am UTC](https://community.unix.com/t/shell-script-help-please/277215/3 "2010-11-12T00:22:21Z")

</div>

```nohighlight
a=`find / -type f -inum +1 -mtime -30 -exec ls -lu {} \; 2>/dev/null | awk '{print $6,$7,$8}'`

b=`find / -type f -inum +1 -mtime -30 -exec ls -lc {} \; 2>/dev/null | awk '{print $6,$7,$8}'`

c=`find / -type f -inum +1 -mtime -30 -exec ls -lc {} \; 2>/dev/null | awk '{print $9}'`

```

removed the spaces in between, yet no output.  
i execute the script but need to do a ctrl + c to escape.

---------- Post updated at 08:22 PM ---------- Previous update was at 08:19 PM ----------

the commands are working seperately of the script so i know it's not a syntax error with the commands at least.

---------- Post updated at 09:22 PM ---------- Previous update was at 08:22 PM ----------

works on a smaller subdirectory but not root directory. perplexed as to why.

---

<div class="post-metadata">

**Author:** ![a\_programmer](https://community.unix.com/letter_avatar/a_programmer/32/6_449c533f586939b6e5f246632a46421f.png) [@a\_programmer](https://community.unix.com/u/a_programmer)\
**Post date:** [November 12, 2010, 12:53am UTC](https://community.unix.com/t/shell-script-help-please/277215/4 "2010-11-12T00:53:47Z")

</div>

Based on the number of volumes/files on your server, find can take a substantial amount of time to search something from /.

Time one of the find commands separately and multiply that time by 3. That is the amount of time your script will probably take before giving any output at all.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_449c533f586939b6e5f246632a46421f.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [November 12, 2010, 9:26am UTC](https://community.unix.com/t/shell-script-help-please/277215/5 "2010-11-12T09:26:31Z")

</div>

Back to first principles.

The commands as posted will not produce any output. They will just put concatonated values into the three environment variables $a $b $c . There is a limited size to an environment variable.  
Also, there is no point to the "-inum +1" cause.

What are you trying to do, and what do you want the output to look like?

---

<div class="post-metadata">

**Author:** ![iluvsushi](https://community.unix.com/letter_avatar/iluvsushi/32/6_449c533f586939b6e5f246632a46421f.png) [@iluvsushi](https://community.unix.com/u/iluvsushi)\
**Post date:** [November 12, 2010, 6:12pm UTC](https://community.unix.com/t/shell-script-help-please/277215/6 "2010-11-12T18:12:51Z")

</div>

hey methyl,  
trying to look for regular files, with one or more inodes, modified within the last 30 days.  
variable a would display time last accessed, b would display time last modified and c would display full path of the file.  
could i have done without the-inum +1? thanks.

---

<div class="post-metadata">

**Author:** ![agama](https://community.unix.com/user_avatar/community.unix.com/agama/32/21613_2.png) [@agama](https://community.unix.com/u/agama)\
**Post date:** [November 12, 2010, 7:18pm UTC](https://community.unix.com/t/shell-script-help-please/277215/7 "2010-11-12T19:18:54Z")

</div>

It's a waste of time to traverse the file tree three times when you only need to do it once. You didn't say which flavour of Unix, but if you have a stat command installed, something like this produces 5 columns of output for each file that matches your find criteria and only one pass across the filesystem (in terms of find) is needed. Output, left to right, is date/time of last access, date/time of last modificaton, and file name.

```nohighlight
find / -type f -mtime -30 | xargs stat -c "%x %y %n"|sed -E 's/[.][0-9]+//g; s/ -[0-9]+//g'

```

The sed just strips decimals from the time and the timezone offset.

Depending on what tools you have installed, the -E option to sed might need to be -R. On a FreeBSD system the stat command will be something like this:

```nohighlight
 xargs stat -f "%Sa %Sm %N"

```

As for whether or not to use -inum...  
The way I read the man page for find, `inum` is used to match a specific inum. As a file can only have one inum using a +1 construct makes no sense (at least not to me).

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_449c533f586939b6e5f246632a46421f.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [November 13, 2010, 7:23pm UTC](https://community.unix.com/t/shell-script-help-please/277215/8 "2010-11-13T19:23:28Z")

</div>

> [@](#):
>
> hey methyl,  
> trying to look for regular files, with one or more inodes, modified within the last 30 days.  
> variable a would display time last accessed, b would display time last modified and c would display full path of the file.  
> could i have done without the-inum +1? thanks.

A regular file will have one inode within the filesystem. That inode has a unique number within the filesystem. That inode number is the number referred to in the "-inum" parameter to "find". It is the same number you get with the "-i" switch to "ls". When there is a hard link to a file within that filesystem it is possible to have more than one name for the same inode number.  
The "-inum +1" switch is pointless in this context.

Without knowing what Operating System and Shell you have it is hard to propose a solution. I see that "agama" has posted a neat solution with the "stat" command which is available on some Operating Systems.
