# How to embed data instead of reading user input from an array?

**URL:** <https://community.unix.com/t/how-to-embed-data-instead-of-reading-user-input-from-an-array/375713>\
**Category:** Shell Programming and Scripting\
**Created:** [June 4, 2019, 8:14am UTC](https://community.unix.com/t/how-to-embed-data-instead-of-reading-user-input-from-an-array/375713 "2019-06-04T08:14:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![baris35](https://community.unix.com/letter_avatar/baris35/32/6_449c533f586939b6e5f246632a46421f.png) [@baris35](https://community.unix.com/u/baris35)\
**Post date:** [June 4, 2019, 8:14am UTC](https://community.unix.com/t/how-to-embed-data-instead-of-reading-user-input-from-an-array/375713/1 "2019-06-04T08:14:19Z")

</div>

Hello,  
I am running under ubuntu1 14.04 and I have a script which is sending given process names to vanish so that I'd see less output when I run most popular tools like `top` etc in terminal window. In usual method it works.  
Whenever I restart the system, I have to enter the same data from keyboard at startup. since it was asking me to enter data from command line, I am unable to run it from `systemd/services` as a startup process. I'm looking for a solution to embed the keywords into below script:

start.sh

```plaintext
#!/bin/bash
echo "Enter process count: "
read processCount
if ! [["$processCount" =~ ^[0-9]+$ ]]
    then
        echo "Sorry integers only"
fi
echo "Enter the process names: "
for (( i=1; i<=processCount; i++ ))
do
    read line
    processList=("${processList[@]}" $line)
done

echo ${processList[@]}

processArray="{"
for (( i=0; i<processCount; i++ ))
do
    processArray+="\"${processList[$i]}\","
done
processArray=${processArray::-1}"}"
echo "#define PROCESS_COUNT $processCount" > hidelib.c
echo "#define PROCESS_LIST $processArray" >> hidelib.c
tail -n +3 "proc_hide.c" >> "hidelib.c"

```

When I run the script, `./start.sh`

```plaintext
$ Enter process count:
> 5
$ Enter the process names: 
> watchdog
> migration
> kworker
> ksoftirqd
> kthreadd

```

What I wish to accomplish is not convert user input to array, just need to add `watchdog` , `migration` and other phrases into this script so that it will run at startup without asking any questions.

I removed all lines but just kept last two lines, and run them like :

```plaintext
echo "#define migration" >> hidelib.c
echo "#define watchdog" >> hidelib.c
echo "#define migration" >> hidelib.c
echo "#define kworker" >> hidelib.c
echo "#define ksoftirqd" >> hidelib.c
echo "#define kthreadd" >> hidelib.c
tail -n +3 "proc_hide.c" >> "hidelib.c"

```

I'd appreciate your recommendation.  
Something opposite of this request:  
[sh shell user input and stote it to a array](https://www.unix.com/shell-programming-and-scripting/45213-sh-shell-user-input-stote-array.html)

Or like this way:

```plaintext
./start.sh 5 watchdog migration kworker ksoftirqd kthreadd

```

Thank you  
Boris

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [June 4, 2019, 9:44am UTC](https://community.unix.com/t/how-to-embed-data-instead-of-reading-user-input-from-an-array/375713/2 "2019-06-04T09:44:31Z")

</div>

Not sure what you're after, but a construct like

```nohighlight
for KW 
  do echo "#define $KW"
  done

```

inside your `start.sh` will yield

```nohighlight
#define watchdog
#define migration
#define kworker
#define ksoftirqd
 #define kthreadd

```

when called like

```nohighlight
./start.sh watchdog migration kworker ksoftirqd kthreadd

```

If you need the count, use `$#` .

Redirect to taste...

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/6_449c533f586939b6e5f246632a46421f.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [June 4, 2019, 12:05pm UTC](https://community.unix.com/t/how-to-embed-data-instead-of-reading-user-input-from-an-array/375713/3 "2019-06-04T12:05:08Z")

</div>

```nohighlight
#/bin/bash
if [$# -eq 0]
then
   echo "usage:
   $0 procnames ..."
  exit 1
fi
{
echo "#define PROCESS_COUNT $#" 
printf "#define %s\n" "$@"
tail -n +3 "proc_hide.c"
} > hidelib.c

```
